如何使用骆驼邮件将带有嵌入式附件的电子邮件发送到Outlook

时间:2019-02-13 16:00:49

标签: apache-camel email-attachments apache-camel-mail

与骆驼邮件一起发送时,Outlook 2016将无法正确显示带有text / html内联附件的电子邮件。

同一封电子邮件在其他邮件客户端(如Apple Mail)中正确显示。

我已经尝试过交换邮件本身的内容类型以及附件的内容类型。

当内容类型设置为text / rich时,将显示嵌入式附件,但电子邮件正文最终将作为常规附件。

如果电子邮件的内容类型为text / html,则正文将正确显示,但附件最终将作为常规附件而不是内联。

添加附件的处理器:

  String emailContent = emailBody.getContent().toString();

  byte[] emailContentByte = emailContent
          .getBytes("UTF-8");


  // add the file as an attachment to the exchange with a text/html format.
  exchange.getIn().addAttachment("cid:http-email", new DataHandler(
          (DataSource) new ByteArrayDataSource(emailContentByte,
                  "text/html")));

骆驼smtp端点和标头:

        .setHeader("contentType", constant("text/html"))

        .process(new AttachmentBuilder())

        .to("velocity:{{mail.template}}?encoding=UTF-8")

        //send the exchange to the specified email address.
        .toD("smtp://{{mail.smtp.host}}:{{mail.smtp.port}}"
                + "?from={{mail.smtp.from}}"
                + "&to={{mail.smtp.to}}"
                + "&useInlineAttachments=true")

1 个答案:

答案 0 :(得分:2)

我认为整个邮件的内容类型应为Content-Type: multipart/related

text/html将是各个消息部分的内容类型。

也许this q/a from stackoverflow会有所帮助。它与图像有关,但要点是周围消息的内容类型。