使用Mule的IMAP传输时如何解析入站电子邮件? [英] How to parse inbound e-mail when using Mule's IMAP transport?

查看:79
本文介绍了使用Mule的IMAP传输时如何解析入站电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我才刚刚开始学习m子,所以如果这是一个非常基本的问题,请原谅我.

I am just starting to learn mule so please forgive me if this is a very basic question.

我已经成功配置了ule子来监视我的邮箱,因此无论何时收到邮件,我都会将邮件写到文本文件中(仅用于测试).

I have successfully configured mule to monitor my mail box so whenever a mail comes in I write the mail to text file (just for testing).

现在,我需要解析此邮件并从邮件中获取消息/发件人/收件人.

Now I need to parse this mail and get the message / From / To from the mail.

<flow name="testFlow" doc:name="testFlow">
        <imap:inbound-endpoint host="ip"
            port="143" user="username" password="pwd" doc:name="IMAP"
            responseTimeout="10000" transformer-refs="Message_Properties">
        </imap:inbound-endpoint>
        <file:outbound-endpoint path="C:\"
            outputPattern="#[function:datestamp].dat" doc:name="File">
        </file:outbound-endpoint>
    </flow>

我认为我可以使用下面的表达式(使用表达式转换器)来获取标头信息

I thought I would be able to get the header information using the below expression (using expression transformer)

#[inboundProperties['email-header-name']] 

但是这似乎不起作用.我也尝试了以下表达式,但是没有用

but this doesn't seem to work. I also tried the below expressions but didn't work,

#[map-payload:HOST]
#[map-payload:MESSAGE]
#[map-payload:TIMESTAMP]

有人可以帮忙吗?还有人知道是否有包含可用表达式列表的文档吗?

Can someone help? Also does anyone know if there is a document with the list of available expressions?

我包括了记录器以查看属性,并且它显示了所有属性,但找不到正文..此外,我尝试使用

I included the logger to view the properties and it displayed all the properties but I couldnt find the body.. Also, I tried getting the fromAddress using

#[map-payload:fromAddress] and #[inboundProperties['fromAddress']] 

但是没用,有人可以让我知道我哪里错了吗?

but didn't work, can someone let me know where I am wrong?

属性如下所示,

inbound.fromAddress=Service <service@xx.com> 
inbound.subject=Test Final inbound.toAddresses=Service

这是我尝试过的方法,但是不起作用:(

This is what I have tried but doesnt work :(

我正在尝试检索电子邮件主题并写入文件,或者只是使用基于电子邮件主题的记录器来显示它,但出现以下错误.

I am trying to retrieve the email subject and write to file or just show it using logger based on email subject but I am getting the below error.

ERROR 2013-02-07 19:22:45,275 [[test].connector.file.mule.default.dispatcher.01] org.mule.exception.DefaultMessagingExceptionStrategy:
********************************************************************************
Message : Could not find a transformer to transform "SimpleDataType{type=javax.mail.internet.MimeMessage, mimeType='*/*'}" to "SimpleDataType{type=java.io.InputStream, mimeType='*/*'}".
Code : MULE_ERROR-236 

您能让我知道我在哪里犯错吗?

Can you let me know where I am making mistake?

<flow name="testFlow1" doc:name="testFlow1">
<imap:inbound-endpoint host="ip"
port="143" user="uname" password="pwd" doc:name="IMAP"
responseTimeout="10000" disableTransportTransformer="true">
</imap:inbound-endpoint>
<logger message="#[message.inboundProperties['inbound.fromAddress']]" level="INFO" doc:name="Logger"/>
<choice doc:name="Choice">
<when expression="message.inboundProperties['inbound.subject']=='plain test'">
<processor-chain>
<logger message="#[message.inboundProperties['inbound.fromAddress']]" level="INFO" doc:name="Logger"/>
</processor-chain>
</when>
<otherwise>
<processor-chain>
<file:outbound-endpoint path="C:\mule" outputPattern="#[function:datestamp].dat" responseTimeout="10000" disableTransportTransformer="true" doc:name="File">
</file:outbound-endpoint>
</processor-chain>
</otherwise>
</choice>
</flow>  

推荐答案

不幸的是,

Unfortunately the IMAP connector documentation doesn't list the message properties created when a new message is received. You can find all the created properties by adding:

<logger level="WARN" />

之后的

.这将在WARN级别记录所有消息元信息,包括属性.

after the imap:inbound-endpoint. This will log all the message meta information, including properties, at WARN level.

您还可以在

You can also find the property names in the MailProperties JavaDoc. For example inbound.fromAddress is the inbound property that contains the sender's email address.

消息正文是文本电子邮件内容,除非它是多部分电子邮件.在这种情况下,如果第一部分是text/plain,它将被设置为邮件有效负载,否则所有部分都将作为入站邮件附件可用.

The message body is the text email content, unless it's a multi-part email. In that case, if the first part is text/plain, it will be set as the message payload, otherwise all parts will be available as inbound message attachments.

这篇关于使用Mule的IMAP传输时如何解析入站电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆