Saturday, October 18, 2008

Tricks in Java Emailing

In my earlier post Java Class to Implement Email, I have shown you how you can effectively send mail using Java class, provided you have an SMTP server in your hand. This article will tell you how you can enhance it by setting different property of message and the server you are using. Kindly refer the code (in previous article) in which section you need to add those lines of code to get those affected.




1. How to set the return path of the email?

The return path of the email is by default the email id from which the email is sent. However, different from the sender, it can be easily done by setting the property of the server.

properties.put("mail.smtp.from",your-name@your-domain.com);




2. How to set the importance of the Email Message to high and Sensitivity of Email?


Importance and the sensitivity are the two important property of the message. You can easily set it using setHeader() method of the MimeMessage.

message.setHeader ( "X-Priority", "High" ) ;
message.setHeader ( "Sensitivity", "Company-Confidential" ) ;
message.setHeader ( "Importance", "High" ) ;



3.How to set the reply to option?


If you are familiar with Microsoft Outlook, you probably have used the “Having Replies Sent” mailing option. This enables a sender to identify the intended person to whom the replies should be sent. While experimenting with Java Mail, I found it very simple to do it using setReplyTo() method of the MimeMessage.

message.setReplyTo(new InternetAddress[] { new InternetAddress(your-name@yourdomain.com)});


The figure tells us the major classes and interfaces comprising the Java Mail API, which I missed earlier.




3 comments:

Martin Svitek said...

Thanks for a post.

Unknown said...

thanks for the post

Anonymous said...

Hey just wanted to give you a quick heads up. The words in your article seem to be running off the screen in Safari.
I'm not sure if this is a formatting issue or something to do with
internet browser compatibility but I figured
I'd post to let you know. The layout look great though! Hope you get
the problem resolved soon. Many thanks

Visit my web page mima

Total Pageviews