JavaMail Issue with From Attribute
I am using JavaMail to send automated emai开发者_运维百科ls from my java code. Following is the code I use to set the 'from' and 'to' attribute.
message.setFrom(new InternetAddress("XYZ@company.com", "XYZ's alias"));
message.addRecipients(Message.RecipientType.TO, receiverArray);
where receiverArray
is of type InternetAddress[]
and contains all the recipients email addresses.
Everything works fine with the functionality and the receiver is receiving the mail but when we open the mail in MS Outlook 2007, the sender
is shown as XYZ's alias[XYZ@company.com]
and to
is shown as the receiver's alias only, may be taken from company's Active Directory on which one can double-click and check the properties.
I need the same to be done for the sender also, i.e. only the alias is shown and not the actual email id.
Maybe some sort of mapping has to be done between the email id I mention in from
clause and the active directory.
Both the to
and from
have registered aliases with the company's Active Directory.
Kindly help.
Thanks in advance.instead of adding the recipient using a string, try an InternetAddress object. This will give you addresses in RFC 2047 encoding
http://javamail.kenai.com/nonav/javadocs/javax/mail/Message.html#addRecipients(javax.mail.Message.RecipientType, javax.mail.Address[])
精彩评论