从Spring Integration入站电子邮件适配器下载的电子邮件中提取附件的问题

时间:2019-05-24 18:40:17

标签: spring email adapter integration inbound

我有一个Spring Integration应用程序,该应用程序由在应用程序上下文中配置的邮件入站适配器组成,以轮询POP3电子邮件收件箱以处理包含大型XML文件附件的电子邮件。

我有一个处理程序类(服务激活器),用于从邮件入站通道适配器移交的每封电子邮件中提取附件。

此设置在我们当前使用Spring Integration 2.1的生产应用程序中正常运行。现在,我们有一个迁移到Spring Integration 5.1.4的要求,并且同一应用程序在从电子邮件中提取附件的过程中引发错误。请参考源代码片段2

此安装程序在Spring Integration 2.1版本上可以正常工作,但是在Spring Integration 5.1.4中遇到错误,指示邮箱文件夹未打开。期望是

processMsg(): Mail messaging error processing message     javax.mail.MessagingException: No inputstream from datasource;

嵌套的异常是:         java.lang.IllegalStateException:文件夹未打开

Spring集成配置

<int:channel id="emailInputChannel"/> 
<int-mail:inbound-channel-adapter id="pop3EmailAdapter" store-uri="pop3://    ${pop3.user}:${pop3.pwd}@${pop3.server.host}/Inbox" 
channel="emailInputChannel" should-delete-messages="true" auto-startup="true" 
java-mail-properties="javaMailProperties">               
    <int:poller max-messages-per-poll="1" fixed-delay="${email.poller.rate}" />
</int-mail:inbound-channel-adapter>

<!-- Java Mail POP3 properties -->
<util:properties id="javaMailProperties">
  <beans:prop key="mail.debug">true</beans:prop> 
  <beans:prop key="mail.pop3.port">${pop3.server.port}</beans:prop> 
</util:properties>

<!-- Email Handler configuration -->
<si:service-activator id="emailAttachmentsHandler"
    input-channel="emailInputChannel" ref="emailMessageHandler" method="extractEmailAttachments">
</si:service-activator>

<beans:bean id="emailMessageHandler" class="EmailMessageHandler"/>

电子邮件消息处理程序Java源代码片段2

public List<org.springframework.messaging.Message<?>> extractEmailAttachments(Message emailMsg) throws Exception {  
List<org.springframework.messaging.Message<?>> attachmentList = null;

logger.info("LookoutEmailAttachmentSplitter.extractEmailAttachments: Received Message: " + emailMsg);

attachmentList = processMsg(emailMsg);  


}

    private List<org.springframework.messaging.Message<?>> processMsg(javax.mail.Message emailMsg) throws MessagingException {
    int max;
    Multipart mp;
    Object content;

    try {
        // getting the contents of the message
        logger.info("processMsg(): Message: " + emailMsg);

        content = emailMsg.getContent();

        // Check the content to verify if it has multipart attachments. 
        if (!(content instanceof Multipart)) 
            return attachmentList;
     }
     catch (Exception ex){
       logger.info("processMsg(): Error: " + ex.getMessage());
     }

}

0 个答案:

没有答案