使用Apache Camel获取邮件附件信息

时间:2017-04-30 14:52:37

标签: java apache-camel apache-camel-mail

如何使用Apache Camel获取已有Exchange对象的邮件附件信息?

1 个答案:

答案 0 :(得分:4)

如果您有maven项目,则可以使用此依赖项:

<dependency>
        <groupId>org.apache.camel</groupId>
        <artifactId>camel-mail</artifactId>
        <version>x.y.z</version>
</dependency>

然后如果您已有Exchange对象,可以尝试:

Message message = exchange.getIn();
    if (message.getAttachments().size() > 0) {
        for (Map.Entry<String, DataHandler> entry : messageCopy.getAttachments().entrySet()) {
            DataHandler dataHandler = entry.getValue();
            //get the document filename                
            String attchmentFilename = dataHandler.getName();
            String decodedFilename = MimeUtility.decodeText(attchmentFilename);
            //get inputstream of attachment file
            InputStream is = dataHandler.getInputStream();              
            //generic function for extracting attachment content
            extractor(is);
        }
    }

我建议在提取器功能中使用Apache Tika来获取附件内容和其他信息