Question

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

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?

EDIT:

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?

The properties are something like below,

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

Edit 2:

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>  
Was it helpful?

Solution

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" />

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top