2

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("testemail@test.ch");
    email.setSubject(subject);
    email.setMsg(message);
    email.addTo(to);
    email.send();

So I'd like to substitute "testemail@test.ch" with the name.

Thanks,

andreybavt
  • 1,301
  • 4
  • 17
  • 32

2 Answers2

3

Try setting sender's email as below.

 email.setFrom("John Doe<testemail@test.ch>");

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

Shishir Kumar
  • 7,981
  • 3
  • 29
  • 45
3

Take a look at the Doc... there are 3 Email.setFrom(...) methods JavaDoc and you are using the wrong one.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97