Substitute sender email address with a name in Apache commons email

Is there a way to show sender’s name instead of an e-mail address when sending an e-mail?

This is what I’m currently doing :

Email email = new HtmlEmail().setStartTLSRequired(true);
    email.setDebug(false);
    email.setHostName("smtp.test.ch");
    email.setSmtpPort(587);
    email.setAuthentication("***", "***");
    email.setFrom("[email protected]");
    email.setSubject(subject);
    email.setMsg(message);
    email.addTo(to);
    email.send();

So I’d like to substitute “[email protected]” with the name.

Thanks,

Answer

Try setting sender’s email as below.

 email.setFrom("John Doe<[email protected]>");

This will show the name of sender as John Doe in receiver’s inbox.

Leave a Reply

Your email address will not be published. Required fields are marked *