簡體   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