Sending a CSV File Through Email Using SMTP
home
Shows how to use the SMTP connector to facilitate an information transfer through email. It also illustrates how you can use the File connector to input a CSV file and transform it using DataMapper.
Example
In this example, a CSV file containing sample sales data is stored in the local directory. This file is converted to the JSON format using DataMapper. The result is sent to an email address using the SMTP connector. DataMapper also computes the total price for each order by multiplying the unit price with the number of units. This example has been configured to use Google Gmail.
Set Up and Run this Example
Open the project in Anypoint Studio.
Create a folder called input under src/main/resources and paste the input.csv file into the input folder. Edit the path field in the file connector to:
Path=src/main/resources/input
Click the SMTP connector and configure its properties as follows:
Host=smtp.gmail.com Port=587 User=senderemailid%40gmail.com Password=senderpassword To=receiveremailid@gmail.com From=senderemailid@gmail.com Subject=Export from Excel
Run the project as a Mule application.
Login to receiveremailid@gmail.com to verify if the sales data was received via email. You should get an email that has the following content:
[{orderId=1, name=aaa, units=2.0, pricePerUnit=10.0, totalPrice=20.0}, {orderId=2, name=bbb, units=4.15, pricePerUnit=5.0, totalPrice=20.75}]