Francesco
Francesco

Reputation: 325

java Message displayed sender name/surname

I'm using in a java application the javax.mail.internet.MimeMessage to send mail message via javax.mail library.

In the message creation class I use something like:

message.setFrom(new InternetAddress("[email protected]"));

The message when received show in the message header:

From: <[email protected]>

with any mail client software is possible to specify the 'displayed' sender, and in that case the header looks like:

From: Name Surname <[email protected]>  

where "Name Surname" is a free string, like also "CompanyName commercial office", and it is what in general mail client shows about message sender.

How can I set the 'displayed' sender into the message object? message.setFrom(String s) doesn't work.

Upvotes: 1

Views: 570

Answers (1)

StephaneM
StephaneM

Reputation: 4899

Just use the constructor with the personal parameter:

message.setFrom(new InternetAddress("[email protected]","Name Surname"));

See http://docs.oracle.com/javaee/6/api/javax/mail/internet/InternetAddress.html#InternetAddress%28java.lang.String,%20java.lang.String%29

Upvotes: 2

Related Questions