Sending a CSV file through email using SMTP Connector

(1 review)

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.

a58cd5b0-Screen Shot 2018-08-06 at 1.44.45 PM.png

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

  1. Open the "Sending a CSV file through email using SMTP Connector" project in Anypoint Studio from Anypoint Exchange.
  2. 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 properties to <yourPath>/input/input.csv.
  3. 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
  4. Run the project as a Mule application.
  5. 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
   }
 ]

Reviews

TypeExample
OrganizationMuleSoft
Published by
MuleSoft Organization
Published onSep 6, 2018
Asset overview

Asset versions for 2.1.x

Asset versions
VersionActions
2.1.4