使用 Camel 发送带有自定义 MIME 消息的邮件

Sending mail with a custom MIME Message using Camel

我想使用 Camel 发送多部分 MIME 消息(自定义 headers、纯文本和 HTML)。我可以在源代码中看到,如果我将 Camel 消息的 body 中的 javax.mail.internet.MimeMessage 发送到邮件组件,它会在不创建新邮件组件的情况下发送它。但是为了创建一个新的 MimeMessage,您至少需要一个 javax.mail.Session,这样您就可以编写 MimeMessage msg = new MimeMessage(session)。我怎样才能在 Camel 中获得 session?

如果我没记错的话,在 Spring 集成中,邮件出站通道适配器需要一个 JavaMailSender 来完成它的工作,你可以向这个 JavaMailSender 询问一个新的 MimeMessage 因为它有 Session。我如何用 Camel 做同样的事情?

提前致谢。

您不需要 session。

您可以将 text/html 消息构建为您的 body,然后指定一个 header 来保存您的明文 body。查看文档中的 alternativeBodyHeader 选项。这样,Camel 将为您构建 multi-part 消息。