Sending a CSV file through email using SMTP Connector
home
This example shows you how to use the SMTP connector to facilitate information transfer through email. It also illustrates how you can use the File connector to input a csv
file and then tranform the content of that file by using the DataWeave Transform component.
Assumptions
This document describes the details of the example within the context of Anypoint™ Studio, Mule ESB’s graphical user interface (GUI). This document assumes that you are familiar with Mule ESB, DataWeave and the Anypoint Studio interface.
Example Use Case
In this example a .csv
file containing sample sales data which is stored in the local directory is converted to the collection of Maps using the Transform component. This collection is sent to an email address using the SMTP connector. The Transform component also computes the total price for each order by multiplying the unit price by the number of units. This example has been configured for Google's Gmail.
Set Up and Run this Example
- Open the "Sending a CSV file through email using SMTP Connector" project in Anypoint Studio from Anypoint Exchange.
- Create a folder called
input
undersrc/main/resources
and paste theinput.csv
file into theinput
folder. Edit the path field in the File connector properties to<yourPath>/input/input.csv
. - Double-click
src/main/resources/mule-artifact.properties
and configure its properties as follows: smtp.user=@gmail.comsmtp.password=smtp.host=smtp.gmail.comsmtp.port=587mail.from=@gmail.commail.to=@gmail.commail.subject=Export from Excel - Run the project as a Mule application.
- Log in to
<receiver-email-ID>@gmail.com
to verify that the sales data was received via email. The email should contain the following content:
[
{
"name": "T-shirt",
"orderId": "1",
"pricePerUnit": "10",
"units": "2.0",
"totalPrice": 20.0
},
{
"name": "Jacket",
"orderId": "2",
"pricePerUnit": "5",
"units": "4.15",
"totalPrice": 20.75
}
]