简体   繁体   English

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

[英]Sending mail with a custom MIME Message using Camel

I want to send a multipart MIME message (custom headers, plain text and HTML) using Camel. 我想使用骆驼发送多部分的MIME消息(自定义标头,纯文本和HTML)。 I can see in the source code that if I send a javax.mail.internet.MimeMessage in the body of a Camel message to the mail component, it send it without creating a new one. 我可以在源代码中看到,如果我将Camel消息正文中的javax.mail.internet.MimeMessage发送到邮件组件,它将在不创建新消息的情况下发送它。 But in order to create a new MimeMessage you need to have at least a javax.mail.Session so you can write MimeMessage msg = new MimeMessage(session) . 但是,为了创建一个新的MimeMessage您至少需要有一个javax.mail.Session以便您可以编写MimeMessage msg = new MimeMessage(session) How can I obtain that session in Camel? 我如何在Camel中获得该会话?

If I remember correctly, in Spring Integration the mail outbound channel adapter need a JavaMailSender to do its job and you can ask this JavaMailSender for a new MimeMessage because it have the Session . 如果我没记错的话,在Spring Integration中,邮件出站通道适配器需要一个JavaMailSender来完成其工作,并且您可以向该JavaMailSender请求一个新的MimeMessage因为它具有Session How I do the same thing with Camel? 我如何用骆驼做同样的事情?

Thanks in advance. 提前致谢。

You don't need the session. 您不需要会话。

You can build the text/html message as your body, but then specify a header to hold your plaintext body. 您可以将text/html消息构建为正文,但是可以指定标头来保存纯文本正文。 Check out the alternativeBodyHeader option in the docs. 在文档中签出alternativeBodyHeader选项。 In this way, Camel will build your multi-part message for you. 这样,骆驼会为您建立多部分的信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM