如何从spring集成消息中获取电子邮件的内容(电子邮件正文和附件)?

时间:2019-07-02 15:15:56

标签: java spring spring-integration javamail

所以我集成了Spring Integration以接收邮件,并且一切正常。

我尝试将有效载荷(字节数组)转换为字符串。输出分为未处理的部分。

@ServiceActivator(inputChannel="emailChannel")
public void handleMessage(Message message, @Header("campaign_id") String campaign_id, @Header("tenant_identifier") String tenant_identifier) {
    try {
        TenantContext.setTenantId(tenant_identifier);

        emailCampaignService.recieveMailMessage(message, campaign_id);
    } catch (Exception e) {
       log.error("RecieveMailException{0}", e.getMessage());
    }finally {
        TenantContext.clearTenantId();
    }
    System.out.println(" campaign_id: " + campaign_id );
}

我正在尝试访问电子邮件的内容和附件,但没有成功。我相信这与邮件有效负载有关。

现在ImapAdapter如下:

private IntegrationFlow createImapAdapter(字符串协议,字符串主机,整数端口,字符串inboxFolder,字符串用户名,字符串密码,Long campaignId,字符串tenantIdenifier){         IntegrationFlow流= IntegrationFlows                 .from(Mail.imapInboundAdapter(imapUrl(协议,主机,端口,inboxFolder,用户名,密码))                         .javaMailProperties(p-> p.put(“ mail.debug”,“ false”))                         .searchTermStrategy(((supportedFlags,文件夹)-> {                             标志标志=新标志(Flags.Flag.SEEN);                             返回新的FlagTerm(flags,false);                         })                         .userFlag(“ CLC”)// SI测试服务器需要-如果服务器支持/ SEEN,则不需要                         .headerMapper(new DefaultMailHeaderMapper()),e-> e.autoStartup(true)                         .poller(p-> p.fixedDelay(1000)))                     .enrichHeaders(s-> {                         s.header(“ campaign_id”,新的StaticHeaderValueMessageProcessor(campaignId.toString()));                         s.header(“ tenant_identifier”,新的StaticHeaderValueMessageProcessor(tenantIdenifier));                     })                 .channel(“ emailChannel”)                 .get();

    return flow;
}

,消息内容采用这种格式(例如):

-000000000000f8ac18058cc6e3b0 内容类型:文本/纯文本; charset =“ UTF-8”

这是我想要的内容

-000000000000f8ac18058cc6e3b0 内容类型:text / html; charset =“ UTF-8”

这是我想要获得的内容

-000000000000f8ac18058cc6e3b0-

0 个答案:

没有答案