4 Easy Steps to send Email via Gmail using Mule4

Send Email with 100% automation using Mulesoft

Souptik Das

--

Step 1) Go to your Gmail account settings and enable 2-step verification : https://myaccount.google.com/security

after enabling 2-step verification generate a 16 digit App Password as shown in the below diagram:-

Step 2) Open Anypoint Studio and get Email-Send connector from the Mule palette

Step 3) Configure the connector accordingly:

General connections:-

Host: smtp.gmail.com

Port: 587

User: your email address

password: 16 digit App-password

Advanced configuration:-

After clicking the Advanced Tab, select Edit inline from the Properties section and set the property:

key: mail.smtp.starttls.enable

value: true

Step 4) Configure the Basic connector settings accordingly:

From address: your email address

To address: target email address to whom you want to send the mail (can be multiple)

Subject: Mail Subject

Body: Mail Body

Now deploy the application and voila! Now you can send mail to anyone with 100% automation using Mule 4 !!

Configuration Xml for Reference:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:email="http://www.mulesoft.org/schema/mule/email" xmlns:http="http://www.mulesoft.org/schema/mule/http"
xmlns="http://www.mulesoft.org/schema/mule/core"
xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/email http://www.mulesoft.org/schema/mule/email/current/mule-email.xsd">
<http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="a202eebd-1462-4ec3-ae35-ecf0cc45333e" >
<http:listener-connection host="0.0.0.0" port="8081" />
</http:listener-config>
<email:smtp-config name="Email_SMTP" doc:name="Email SMTP" doc:id="2634bcbe-863b-4b4c-8c2a-1fa9b54120a5" >
<email:smtp-connection host="smtp.gmail.com" port="587" user="your-email@gmail.com" password="16-digit-app-password" >
<email:properties >
<email:property key="mail.smtp.starttls.enable" value="true" />
</email:properties>
</email:smtp-connection>
</email:smtp-config>
<flow name="smtp_mailFlow" doc:id="0062efd2-6fd4-46f7-9e62-8c2450eff394" >
<http:listener doc:name="Listener" doc:id="b951bee7-d0d4-436a-ac34-68413b0c5a70" config-ref="HTTP_Listener_config" path="/mail"/>
<set-payload value="Hello World!" doc:name="Set Payload" doc:id="4c8ec783-7843-4a02-aeab-4ac427fe1991" />
<email:send doc:name="Send" doc:id="be5a1784-13a7-4924-ae0b-5b133c796a14" config-ref="Email_SMTP" fromAddress="your-email@gmail.com">
<email:to-addresses >
<email:to-address value="target-email@gmail.com" />
</email:to-addresses>
</email:send>
<logger level="INFO" doc:name="Logger" doc:id="eaf046fe-7dfa-4354-974c-c4c8a5d7faf4" message="#[payload]"/>
</flow>
</mule>

--

--