Importing an Email Attachment using the IMAP Connector
home
Shows you how to use the IMAP connector to facilitate information transfer through email. It also illustrates how you can use the DataMapper to transform a CSV file to XML.
Note: DataMapper is deprecated and has been replaced by DataWeave.
Example
In this example a CSV file containing sample sales data which has been received as an attachment in an email inbox is imported using the IMAP connector. The DataMapper then converts the CSV file to the XML format. The logger then logs this data on the studio console.
Set Up and Run this Example
- Open the project in the Anypoint Studio interface.
- Click the IMAP Connector in the Mule flow and edit its properties as follows:
imap.server=imap.googlemail.com imap.port=993 imap.user=receiveremailaddress%40gmail.com imap.password=receiver\_password
- Run the project as a Mule application.
- Navigate to src/main/resources to find the input.csv file. Use any email address to send the 'input.csv' file as an attachment to receiveremailaddress@gmail.com
- If you have configured and run this example correctly, the CSV file should appear in the xml format in the studio console. The log message should be similar to what this:
INFO 2017-07-07 10:39:43,897 [[imap-to-xml].imap-to-csvFlow1.stage1.02]org.mule.api.processor.LoggerMessageProcessor: recieved: <?xml version="1.0" encoding="UTF-8"?> < orders> < order> < orderId>1< /orderId> < name>aaa< /name> < units>2.0< /units> < pricePerUnit>10< /pricePerUnit> < /order> < /orders> < orders> < order> < orderId>2< /orderId> < name>bbb< /name> < units>4.15< /units> < pricePerUnit>5< /pricePerUnit> < /order> < /orders>
- After processing the attachment, it is saved in src/tests/resources/output folder in XML format.
Documentation
Read full documentation in GitHub