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

Related

  • The Real-time Data Transfer Magic of Doris Kafka Connector's "Data Package": Part 1
  • Designing a Java Connector for Software Integrations
  • Kafka JDBC Source Connector for Large Data
  • Make Your Integration Seamless By Using Ballerina Client Connectors

Trending

  • The Trust Surface: The Missing Complement to Attack Surface
  • Engineering Production Agentic Systems: An Introduction
  • Build Your Own Local AI QA Engineer With Docker, Ollama, LibreChat, and Playwright MCP
  • OpenTelemetry's OpAMP Potential Far Beyond Supporting Collectors

Mule Email Connector

This article will guide you through the steps of how to use an email connector in the Mule Application. Read below for the tutorial!

By 
Karan Gupta user avatar
Karan Gupta
·
Jan. 25, 22 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
7.9K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we are going to explore all the features provided by mule Email Connector. Email connector helps you to Send, Mark, List, and Delete Emails. We see a simple demo for each of these features now. 

Before starting with developing the Mule Application we need to do some configuration settings in the Gmail account. 

  1. Open your Gmail account and navigate to  Settings --> See all settings options.
  2. Now navigate to forwarding to POP/IMAP option to enable it.
  3. Once this is done, now we need to open Google Account and enable the Less Secure App access, for which go to Manage your Google Account and in search box type Less Secure App access.
  • Now we are ready to start. Open your Anypoint Studio and drag and drop Email Connector from Add Modules as below.
    • Send: 
      • Send Email connector helps you to send mail over SMTPs server. You can also send Attachments through this. Let us configure the connector now.
      • Drag and drop Http Listner and Send Email Connector in a flow and configure the same.
      • Now Configure both the components as below.
        • HTTP Listner Config:
        • Send Mail Config: While configuring this make sure you select connection as SMTPS connection and also tick the Insecure checkbox.
        • Now, we need to configure Send Components properties.
          • If you want to send an attachment you need to define the file extension in the Attachment section. In our demo, we will be sending a .txt file as an attachment. 
          • Also, you can send multiple files as attachments. 
          • Now from Postman hit the above application and you will see an Email in your inbox with one attachment.
    • List:
      • This will give the List of emails available in your mailbox. You can list all the emails or filter it based on certain options provided by the connector. We are going to use the List IMAP component to list available mails in our mailbox.
      • Below is the Flow and Respective connector configuration:
        • List IMAP Config: While configuring this make sure you select IMAPS connection and also tick the Insecure checkbox.
        • In the properties config, you can set the Match with the filter to do the filtering. Also, you can restrict the number of emails you want to retrieve by setting the limit value, -1 indicates all the mails. 
      • Now, from the postman, hit the above application and you will see the list of emails there in your inbox. Check the output it has attachments and attributes with all the details.
      • JSON
         
        [
            {
                "inboundAttachmentNames": [],
                "exceptionPayload": null,
                "inboundPropertyNames": [],
                "outboundAttachmentNames": [],
                "payload": {
                    "attachments": {
                        "hello.txt": "Hello"
                    },
                    "body": "Test"
                },
                "outboundPropertyNames": [],
                "attributes": {
                    "headers": {
                        "Return-Path": "<[email protected]>",
                        "Received": "",
                        "From": "[email protected]",
                        "To": "[email protected]",
                        "Message-ID": "",
                        "Date": "Fri, 14 Jan 2022 14:42:11 +0530 (IST)",
                        "Subject": "Test",
                        "MIME-Version": "1.0",
                        "Content-Type": "multipart/mixed;\r\n boundary=\"----=_Part_0_1243330334.1642151531229\""
                    },
                    "subject": "Test",
                    "flags": {
                        "answered": false,
                        "seen": true,
                        "deleted": false,
                        "draft": false,
                        "recent": false
                    },
                    "ccAddresses": [],
                    "fromAddresses": [
                        "[email protected]"
                    ],
                    "bccAddresses": [],
                    "toAddresses": [
                        "[email protected]"
                    ],
                    "number": 1,
                    "sentDate": "2022-01-14T14:42:11",
                    "id": "25",
                    "replyToAddresses": [
                        "[email protected]"
                    ],
                    "receivedDate": "2022-01-14T14:42:15"
                }
            }
        ]

         

    • Mark as Read:

      • This will mark the emails in your inbox to read. In this, we need to first fetch the Mail id using the List mail component and then pass that id to Mark as a read component for this activity. Below is the flow and the config:

      • Mark as Read Config: You need to use the same connection config we created above for List mails. In the properties, section pass the id received in the output of the List mail component.

      • Now run the code and you will see the mail in your inbox marked as read.

    • Mark as Delete:

      • Marks an incoming email as Deleted. Emails that are marked for deletion are scheduled for deletion when the folder closes, which means that the email is not physically eliminated from the mailbox folder, but its state changes.

      • All these marked emails are deleted when the Delete or Expunge folder is executed.

        • Mark as Deleted config: 

    • Delete: 

      • This will delete the email with the specified email id from the inbox.

      • Also, this will delete the emails that were marked as deleted. 

Connector (mathematics)

Opinions expressed by DZone contributors are their own.

Related

  • The Real-time Data Transfer Magic of Doris Kafka Connector's "Data Package": Part 1
  • Designing a Java Connector for Software Integrations
  • Kafka JDBC Source Connector for Large Data
  • Make Your Integration Seamless By Using Ballerina Client Connectors

Partner Resources

×

Comments

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

  • RSS
  • X
  • Facebook

ABOUT US

  • About DZone
  • Support and feedback
  • Community research

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 215
  • Nashville, TN 37211
  • [email protected]

Let's be friends:

  • RSS
  • X
  • Facebook