MuleSoft Email Connector – Part 1

What is the email link?

MuleSoft Connector for Email sends and retrieves emails via standard email protocols such as SMTPS/SMTP, IMAP, and POP3.

Some use cases for email connectors include:

  • Retrieve emails from POP3 mailboxes
  • Recover, delete and store emails from IMAP mailboxes
  • Sending emails via SMTP

A prerequisite to get started with these how-tos is to add email and file connectors in Anypoint Studio. You can add these connectors from Add units Selection. Also, you must have a Google account because we will be using Gmail to send an email. Also, you need to turn on Gmail Less secure apps Other settings You will not be able to send mail from MuleSoft or any external application.

Let’s first create an SMTP configuration item for global email. To create a generic item, you can go to File Global Elements Click Create and search for Email SMTP.

In the config we have to define a connection as SMTPS connection And check the Unsafe checkbox. Provide details below:

  • host =
  • port = 465
  • User = Your Gmail ID
  • Password = Your Gmail password

SMTP Email Configuration Item Overview

Let’s configure the email sending process to send an email. In the to the titles In the field we have to pass a set of emails to which we want to send an email. in a Content In the body section, we pass the HTML content that we obtained as a result of the template parsing process. In the parsing form, we just associated the blood donation form-register-mail-template.html specified under src/main/resources with an input request.

In the attachments In the Attachments section, we have passed the expression “Blood-Donation.jpg”: vars.image where Blood-Donation.jpg is the name of the attachment and vars.image is the content of the attached file. that image variable Holds the output file read operation. If we want to send multiple attachments, we can define JSON objects.

You can refer to the screenshot below to configure the sending process.

Send process configuration

Our flow will look like this once it’s complete. I have provided the mule flow code at the end.

Complete the Mule flow to send an email with HTML text with an attachment.

Let’s run the test with the postman.

Postman shot

Email Snapshot

Mule flow code for reference:

“” “++item.age++” “++item.bloodType++”

“) JoinBy” “]” doc: name = “create-email-table-content” doc: id = “c741d5e6-9192-42bc-bdde-c444e58db093” />


<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="" xmlns:tls="" xmlns:ee="" xmlns:email="" xmlns:http="" xmlns="" xmlns:doc="" xmlns:xsi="" xsi:schemaLocation="">
	<email:smtp-config name="Email_SMTP" doc:name="Email SMTP" doc:id="60188ae8-00d9-4805-a8d0-ca588189fd57" from=''>
		<email:smtps-connection host="" user="" password="********">
				<tls:trust-store insecure="true" type="jceks"></tls:trust>
				<tls:key-store type="pkcs12"></tls:key>
	<file:config name="File_Config2" doc:name="File Config" doc:id="26d4aa0f-e0ee-4dc6-ade6-9eb0f179010f">
		<file:connection workingDir="C:UsersluffyDownloads"></file:connection>
	<flow name="send-email" doc:id="d8cba714-c4d5-4c15-a68b-cba4cccc807a">
		<http:listener doc:name="listener" doc:id="af9b9af3-1717-4ea7-8bc5-fe04597c5036" config-ref="HTTP_Listener_config" path="/email-send"></http:listener>
		<file:read doc:name="read-attachment-file" doc:id="18d301eb-2bbc-4f6f-8c6e-7d8d2f48266b" config-ref="File_Config2" path="Blood-Donation.jpg" target="image"></file:read>
		<set-payload value="#[%dw 2.0

output text/plain


payload map ((item, index) -> 

  "<tr><td>" ++ ++ "</td><td>" ++ item.age ++ "</td><td>" ++ item.bloodType ++ "</td></tr>") joinBy " "]" doc:name="create-email-table-content" doc:id="c741d5e6-9192-42bc-bdde-c444e58db093"/>
		<parse-template doc:name="parse-email- template" doc:id="2470fbc9-67a8-46d1-bd3b-824f6ea77915" location="blood-donation-registration-mail-template.html"></parse>
		<email:send doc:name="send-mail" doc:id="5e906be9-cfd2-4774-99ae-55b9191b9ed8" config-ref="Email_SMTP" fromAddress="" subject="#["Blood donation registration list"]" toAddresses="#[[""]]">
			<email:body contentType="text/html">
			<email:attachments><![CDATA[#["Blood-Donation.jpg": vars.image]]]></email:attachments>
		<set-payload value="#[%dw 2.0

output application/json 



	"message": "An email has been sent successfully."

}]" doc:name="response" doc:id="8ece226a-7110-48c8-901c-8d9d3a20ea97"></set>

Content of blood donation-register-mail-template.html file for reference:

<!DOCTYPE html>
         table {
         font-family: arial, sans-serif;
         border-collapse: collapse;
         width: 100%;
         td, th {
         border: 1px solid #dddddd;
         text-align: left;
         padding: 8px;
         tr:nth-child(even) {
         background-color: #dddddd;
      <h4>Please find below a list of people who have registered for blood donation.</h4>
            <th>Blood Type</th>

This is. I hope you learned to use the MuleSoft Email Connector to send an HTML email with an attachment.


Leave a Comment