繁体   English   中英

Apache Camel:使用路由将电子邮件保存到文件(.eml)

[英]Apache Camel: save email to file (.eml) using routes

我正在查看电子邮件帐户,这很有效。 我还希望将收到的消息的备份副本作为文件(.eml)。 我试过这样的事情:

from( mailurl+"?username="+username+"&password="+password+"&"+options)
.to( "file://backup?allowNullBody=false&forceWrites=true");

我得到的是每个收到的电子邮件的文件,其中生成的名称如ID-MACHINENAME-2443-1211718892437-1-0在所需目录中,但该文件为空。 我知道我可以使用处理器创建自己的.eml文件,但是,是不是只使用路由更简单的方法呢? 为什么创建的文件为空?

我找到的每个传入电子邮件到.eml文件的备份副本的解决方案是创建一个这样的处理器:

    public void process(Exchange ex) throws Exception {

    javax.mail.Message mailMessage = ex.getIn(org.apache.camel.component.mail.MailMessage.class).getMessage();

    File file = new File( "backupDirectory", "DesiredFileName.eml");
    DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file)));       
    mailMessage.writeTo(os);
    os.close();
}

此解决方案复制整个邮件,包括所有标题,正文和附件。

暂无
暂无

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

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