views:

191

answers:

1

Currently, our application uses a javax.mail to send email, using javax.mail.MailMessage. We set the From headers of the email this way:

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("[email protected]"));

This works just fine, but we'd like to make the "From" section a little more user-friendly. Currently, someone receiving an email will see "[email protected]" in the "From" section of their inbox. Instead, we'd like them to see "Company XYZ" there. I figure this is probably done with the addHeader() method, but I'm not sure what the header name would be.

+1  A: 

OK, reading documentation about ALL the classes involved would have been helpful. The correct syntax should be

Message msg = new MimeMessage(mailSession);
msg.setFrom(new InternetAddress("[email protected]", "Company XYZ"));

Source: http://java.sun.com/products/javamail/javadocs/javax/mail/internet/InternetAddress.html

abeger
It might be worth testing whether "Company XYZ <[email protected]>" allows you to use the IntenetAddress(String, boolean) constructor to strictly check the address syntax but still have a personal name.
erickson