Sending email such that “from” is a name or text rather than real email address
Question
I am sending email using Java Mail API. When the email is received in the inbox its shows the email address used to send the email. I want to hide the from email address and show some text. I think its possible because when I get an email from facebook, in the inbox it says "Facebook - Email subject" rather than "xyz@facebook.com - Email Subject".
I want to do the same using Java Mail API.
Thanks in advance. :)
Solution
Use the Constructor
InternetAddress(String address, String personal)
when building your sender address. In your example this would be
sender = new InternetAddress("xyz@facebook.com","Facebook");
OTHER TIPS
Use this code inside the try block:
// Set From:
message.setFrom(new InternetAddress("displayname<"+from+">"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow