Email Connector in Mule 4.0
This tutorial will explain the email connector send operation in Mule 4.0 with new Anypoint Studio.
Join the DZone community and get the full member experience.
Join For FreeStep 1: Create a New Mule Project named SmptDemo
- Drag and drop an HTTP Listener Connector to get the request for your service and set the host and port numbers. Here, the host is set to mule4.eaiesb.com and port to 9098 and after configuring, test the connection successfully will specify port is in use or not.
- Set the URL path for your email service: / and get the message in the body field of your response property.
- By default Mule 4.0 doesn't have the email Module so in Mule palette click on +Add Module and add the email extension from the list and finish it.
Step 2: Add the Extension and Verify the Following in the Palette
- The earlier Mule version has three different connectors for mail like IMAP, POP3, and SMTP, but the Mule 4.0 version has a single email module that has different operations like Delete, Send, List pop 3, List imap as shown below:
Step 3:
Drag the email connector onto the canvas and configure the SMTP settings. Here, the configuration is Host: smtp.gmail.com , Port: 587 , User: muletest@eaiesb.com and password details of the SMTP as shown:
- Go to the Advanced tab and select inline from properties field and add the following:
- Key: mail.smtp.starttls.enable & Value: true and test that connection is successful.
Step 4: Give the From address within that To address, Subject, and Body details. Select the Content as text here: Hello Mule4 and ContentType as text/plain.
Setting the Body and Content below:
Step 5:
Right-click on canvas and run the Mule Project, and by default, Mule will download the artifacts from the maven repository, and once the project does not have any errors, it will show a successful deployment.
Step 6:
Open the Postman and Hit the Service URL request as shown:
- The message is sent successfully in HTTP response property, and the response set for the request, and we can check the message given in the body within the mail ID set in Value of SMTP Connector and is successfully received as mail body:
Happy learning!
Opinions expressed by DZone contributors are their own.
Comments