Reputation: 1279
We use a GlassFish server (JavaEE 7) with JavaMail. Afaik, the official E-Mail RFC states that mail addresses may look something like this:
Tom Tester <[email protected]>
which would include a nicer representation than using only the email address. The Glassfish server is able to use this when configuring it on the admin console, clients like the GMail web client then display "Tom Tester" as sender. However, I'd like to specify the mail resource in the glassfish-resources.xml
within our project, the configuration file doesn't allow <
or >
, because it's xml. I tried
<mail-resource
from="Tom Tester <[email protected]>"
...
and
<mail-resource
from="Tom Tester [email protected]"
...
, but these configurations won't work. Both approaches end up in sending only "[email protected]" as sender. I also didn't find any specification details from the GlassFish docs. Does somebody know if the desired behaviour is possible?
Upvotes: 1
Views: 143
Reputation: 19831
In case you want to explicitly set the personal name for the sender, you need to do it while creating the email message.
Let's say you have the session mailSession
from the GlassFish Resource and you are creating a message mailMessage
Now you can set the from
attribute of the message:
mailMessage.setFrom(new InternetAddress(mailSession.getProperty("mail.from"), "Tom Tester"));
Read more here.
Upvotes: 1