File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Other JSE/JEE APIs and the fly likes Java Mail: How to display sender's name? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Java Mail: How to display sender Watch "Java Mail: How to display sender New topic

Java Mail: How to display sender's name?

Sherry Chandra

Joined: May 13, 2004
Posts: 4
Hi everyone,
I am new in Java Mail api and i am having a simple problem.
How can i specify the sender name rather then his email address while sending mail.
When i am sending the mail the recepient sees the sender's name as my full email address and not my name.
I would like to specify that name in the mail program.
Hoping for a reply
Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

There is an addFrom(Address[] addresses) method on javax.mail.Message (and more usefully its concrete subclass MimeMessage). Normally you'd add addresses as javax.mail.InternetAddress which has some loose SMTP address validation, conveniently it is loose enough to allow for any string - so you can add a from address which is "Sherry Chandra" easily enough. However remember to set the replyTo address as a valid address - otherwise people will not be able to rely (unless you are using something like Exchange an only expect to be emailing to other people on the same Exchange server).

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
jesudian selvaraj

Joined: May 31, 2012
Posts: 1
Thanks for your reply. But this way it doesn’t pick the contact details from the exchange server. It directly hardcodes the contact that we specify. Is there a way to pick the contact from the server so that clicking on the contact will pop up the complete contact details of the from address in outlook. It works fine for “to address” but not the same way for “from address”. When we send a mail from outlook or browser it works, but not in javamail.

Tim Moores

Joined: Sep 21, 2011
Posts: 2413
That's a function of the email client, not the JavaMail API. Note that JavaMail has no provisions for accessing Outlook and/or Exchange-specific functionality.
I agree. Here's the link:
subject: Java Mail: How to display sender's name?
It's not a secret anymore!