DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

SBOMs are essential to circumventing software supply chain attacks, and they provide visibility into various software components.

Related

  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Troubleshooting Connection Issues When Connecting to MySQL Server
  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Accelerating Connection Handshakes in Trusted Network Environments

Trending

  • Top Load Balancing Algorithms: Choosing the Right Strategy
  • Why API-First Frontends Make Better Apps
  • The Shift to Open Industrial IoT Architectures With Data Streaming
  • How to Build Your First Generative AI App With Langflow: A Step-by-Step Guide

Retrieving Emails and Attachments From Emails in Mule 4

This article describes the way to retrieve email and reads email attachments using the EMAIL connector in Mule 4.

By 
Rajat Pareek user avatar
Rajat Pareek
·
Jul. 26, 19 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
15.0K Views

Join the DZone community and get the full member experience.

Join For Free

Step 1

Create a new Mule project and name it samplemaildemo (You can choose any name).

Step 2

Drag and drop an HTTP listener component to get the request for your service. Specify the host and port and provide a URI path. Make sure to test it, as the port is not being used by any of your other services.

Image title

Step 3

Click on the Add module section in the Mule palette and add the email connector extension, as by default, Mule 4 does not have the Email module.

Image title

Check out the pom file, as the dependency will be added to it.

Image title

Step 4

In Mule 4 under the email connector, you can see different operations like Send, Delete,
List - POP3, List - IMAP, Mark as read, etc. as shown below, whereas in an earlier Mule version, we had 3 different connectors.

Image title

For this tutorial, we will be using the List - POP3 and List - IMAP operations.

Image title

Step 5

Drag and drop the List - POP3 to the right of the HTTP listener in the process section.

Image title

Step 6

Give a display name of your choice or leave it as is. Under Basic Settings, click on add a new connector configuration. Here, we specify our POP3 mailbox server details.

Mule provides both secure and non-secure connections that you can choose for your security settings.

  1. POP3 Connections 

  2. POP3S Connections

For connections, you need the Host, Port, User, and Password details of the respective mail server box.

(Server details — like common mailboxes such as Outlook or Gmail — are easily available over the internet, just Google it.)

Image title

Go to the Advanced tab, and under Properties, select Edit inline and add the below key: mail.pop3.ssl.enable and Value: true

Image title

Specify the timeout connection values as per your requirements.

Step 7

For the POP3S connection, you need to specify the encryption type i.e., TLS. Under the TLS configuration, select Global reference, and under it, add a new Global reference and select the Ensure checkbox, and leave the rest of the fields blank. In case you have a network connection that requires TLS connection to be set up, then get the same and add it to the below configuration, as in this case, we will leave it as it is.

    Image title

<tls:context name="TLS_Context" doc:name="TLS Context" doc:id="6bbe6316-8999-42d5-bb0a-692dfe51a340" >
<tls:trust-store insecure="true"/>
</tls:context>

Or add the above piece of code below the pop3 email configurations and the same (TLS) will be enforced. 

Step 8

Now that we are done with the mail server connections, specify the mailbox folder name from which you want to read the mails. Filter the mail by applying the filter option available. Here, we are using the Edit Inline option and specifying the mail from a specific id whose mail we would like to read and get email attachments.

More specific filters can be applied as per the requirements. Check it out and explore the different options available.

Specify the page size (Size of the page used by the PagingProvider implementation for fetching the emails from the POP3 server)

and Limit as no of emails one wants to retrieve. The default is -1, which reads all the emails received after applying the filter.

Select False for Delete after retrieve.

Image title

To get more details regarding the configurations details, click the below Mule docs link to get more insight about it.

https://docs.mulesoft.com/connectors/email/email-documentation

Step 9

Drag a For Each Scope and place it just after the connector and add a set variable and logger component.

Image title

Change the For each setting as per your requirement or leave it as it is.

Specify a name for a variable and add the below code to the value, it reads the body of the emails retrieved.

 #[payload.body] 

In the logger, print the value of the variable to check it #[vars.value].

Save the project and test it using Postman or SoapUI. Make the get request call to your API and wait for it to get the mail.

Connection (dance)

Opinions expressed by DZone contributors are their own.

Related

  • How to Identify the Underlying Causes of Connection Timeout Errors for MongoDB With Java
  • Troubleshooting Connection Issues When Connecting to MySQL Server
  • Jakarta WebSocket Essentials: A Guide to Full-Duplex Communication in Java
  • Accelerating Connection Handshakes in Trusted Network Environments

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: