Setting the from name in a javax.mail.MimeMessage?

后端 未结 4 2060
生来不讨喜
生来不讨喜 2020-12-08 18:28

Currently, our application uses a javax.mail to send email, using javax.mail.MailMessage. We set the From headers of the email this way:

Message msg = new Mi         


        
4条回答
  •  死守一世寂寞
    2020-12-08 19:21

    OK, reading documentation about ALL the classes involved would have been helpful. The correct syntax should be

    Message msg = new MimeMessage(mailSession);
    msg.setFrom(new InternetAddress("mail@companyxyz.com", "Company XYZ"));
    

    Source: https://javamail.java.net/nonav/docs/api/javax/mail/internet/InternetAddress.html

提交回复
热议问题