简体   繁体   English

Java MimeMessage电子邮件打印标题信息在正文中

[英]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.

相关问题 如何在java中使用mimemessage class获取email正文和附件 - How to get email body text and attachments using mimemessage class in java Java在MimeMessage中添加标头 - Java add header in MimeMessage msg 我尝试在MimeMessage的Java方法中发送带有主体内容附件的电子邮件时,主体内容未发送 - Body content is not being sent while I am trying to send an email with attachment with main body content in Java methods of MimeMessage 如何修改现有的Java邮件MimeMessage正文部分? - How to modify existing Java mail MimeMessage body parts? Java - 将原始电子邮件内容文本 RFC 822 转换为 MimeMessage - Java - Convert the Raw Email Content Text RFC 822 to MimeMessage 如何从MimeMessage Java中的电子邮件中裁剪用户签名 - How to trim off the user signature from Email in MimeMessage java 在使用 Java 和 MimeMessage 发送之前在默认邮件客户端中预览电子邮件 - Preview an email in default mail client before sending with Java and MimeMessage 在Java MimeMessage中设置“ from”标头字段无法正常工作 - Setting the “from” header field in Java MimeMessage not working correctly 带有标题信息但没有正文的HttpUrlConnection Post - HttpUrlConnection Post with header info but no body MimeMessage正文更长76个字符 - MimeMessage body longer 76 chars
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM