从javax.mail.MimeMessage中的名称设置? [英] Setting the from name in a javax.mail.MimeMessage?

查看:169
本文介绍了从javax.mail.MimeMessage中的名称设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前,我们的应用程序使用javax.mail发送电子邮件,使用javax.mail.MailMessage。我们以这种方式设置电子邮件的From标头:

 消息msg = new MimeMessage(mailSession); 
msg.setFrom(new InternetAddress(mail@companyxyz.com));

这个功能很好,但是我们想让From部分更多一些用户-友善。目前,收到邮件的人会在收件箱的发件人部分看到mail@companyxyz.com。相反,我们希望他们在那里看到公司XYZ。我认为这可能是使用addHeader()方法完成的,但我不知道头名称是什么。

解决方案

确定,阅读有关所有相关课程的文档将会有所帮助。正确的语法应该是

 消息msg = new MimeMessage(mailSession); 
msg.setFrom(new InternetAddress(mail@companyxyz.com,Company XYZ));来源: https://javamail.java.net/nonav/docs/api/javax/mail/internet/InternetAddress.html


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 MimeMessage(mailSession);
msg.setFrom(new InternetAddress("mail@companyxyz.com"));

This works just fine, but we'd like to make the "From" section a little more user-friendly. Currently, someone receiving an email will see "mail@companyxyz.com" in the "From" section of their inbox. Instead, we'd like them to see "Company XYZ" there. I figure this is probably done with the addHeader() method, but I'm not sure what the header name would be.

解决方案

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

这篇关于从javax.mail.MimeMessage中的名称设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆