[英]Java MimeMessage email printing header info in body
A code base I inherited is printing out some header info in the body of email. 我继承的代码库是在电子邮件正文中打印出一些标题信息。 This is what is being printed:
这是正在印刷的内容:
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
If I message.writeTo(System.out);
如果我是
message.writeTo(System.out);
right after creating the message, the above text will print out. 创建消息后,上面的文本将打印出来。
Is there a properties file or something somewhere that specifies this stuff? 是否有属性文件或某处指定此内容的东西?
It also looks like when the mail arrives the outgoing server has written proper/different header information for these three attributes. 看起来当邮件到达时,传出服务器已经为这三个属性写了正确/不同的标题信息。
Any ideas for removing it? 删除它的任何想法?
Also, here is the whole function: 另外,这里是整个功能:
private String sendConfirmationEmail (String to, String from, String subject, String body, boolean CCSender) {
try
{
String smtpHost = Properties.smtp;
String fromAddress = from;
String toAddress = to;
Properties properties = System.getProperties();
properties.put("mail.smtp.host", smtpHost);
Session session = Session.getInstance(properties, null);
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress(toAddress));
message.setRecipient(Message.RecipientType.BCC,
new InternetAddress(fromAddress));
if (CCSender) {
message.setRecipient(Message.RecipientType.CC,
new InternetAddress(from));
}
message.setSubject(subject);
message.setText(body);
message.saveChanges();
Transport.send(message);
return "1:success";
}
catch(Exception e)
{
return "0:failure "+e.toString();
}
}
These properties are exposed through the java mail api, which are set as header attributes in eg, MimeMessage . 这些属性通过java mail api公开,它们被设置为例如MimeMessage中的头属性。
Message msg = new MimeMessage(session);
msg.setHeader("MIME-Version", "1.0" );
msg.setHeader("Content-Type", "text/plain; charset=us-ascii" );
The headers can in turn be changed by mail servers according to their local policy. 邮件服务器可以根据其本地策略更改标头。 Inter-mail servern communication could well be performed using eg
gzip
compression where another set of headers will be required. 可以使用例如
gzip
压缩来执行邮件间服务器通信,其中将需要另一组报头。
[EDIT] If you observe the source code for MimeMessage
you will see that some headers are set default, like setHeader("MIME-Version", "1.0");
[编辑]如果您观察
MimeMessage
的源代码,您将看到一些标题设置为默认值,如setHeader("MIME-Version", "1.0");
. 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.