Search code examples
javajakarta-mail

Sending email such that "from" is a name or text rather than real email address


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 "[email protected] - 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("[email protected]","Facebook");