我正在尝试用下面的代码将邮件附件与其他正文文本一起发送。将接收邮件的客户机配置为html主体后,一切正常:邮件文本和附件在邮件客户机(outlook、thunderbird)中正确显示。
但是,当我切换到纯文本,附件是不显示/下载-它似乎是“吞没”的电子邮件客户端。这是正常的行为吗?在这两种情况下附件都是可见的,消息应该是什么样子的?非常感谢您的帮助。
@Component
public class MyRouteBuilder3 extends RouteBuilder
{
/*****************************************************************************
* Camel (3.4.0)
* @throws Exception
****************************************************************************/
@Override
public void configure() throws Exception
{
from( "direct:mail" )
.doTry()
.setBody( constant( new Invoice( "111111", "9999999999", "13.03.2020")))
.setHeader( "copyOfBody", simple( "${body}" ))
.to( "velocity://templates/template_txt.vm?encoding=utf-8" )
.setHeader( "plaintext", simple( "${body}" ))
.setBody( simple( "${header.copyOfBody}" ))
.to( "velocity://templates/template_html.vm?encoding=utf-8" )
.setHeader( "contentType", constant( "text/html;charset=UTF-8" ))
.setHeader( "subject", simple( "Your invoice" ))
.setHeader( "from", simple( "sender@localhost.localdomain" ))
.setHeader( "to", simple( "receiver@localhost.localdomain" ))
.process( exchange ->
{
AttachmentMessage attMsg = exchange.getIn( AttachmentMessage.class );
attMsg.addAttachment( "invoice.pdf",
new DataHandler( new FileDataSource( new File( "C:/tmp/invoice.pdf"))));
})
.to( "smtp://127.0.0.1:25?debugMode=true&alternativeBodyHeader=plaintext" )
;
}
}
暂无答案!
目前还没有任何答案,快来回答吧!