Mule Email Connector – DZone Integration

In this article, we are going to explore all the features that mule Email Connector has to offer. Email Connector helps you Send, highlight, list and delete Email messages. We see a simple demo of each of these features now.

Before we start developing Mule app, we need to do some configuration settings in Gmail account.

  1. Open your Gmail account and go to Settings -> See all settings and options.
  2. Now go to Redirect to POP/IMAP option to enable it.
  3. Once this is done, now we need to open a Google account and enable access to less secure apps, For that, go to Manage your Google account and in the search box type Least secure access to the app.
  • Now we are ready to start. Open Anypoint Studio and drag and drop the email link from Add Modules as below.
    • send:
      • Send Email Connector helps you to send mail through an SMTP server. You can also send attachments through this. Let’s configure the connector now.
      • Drag and drop the Http Listner and send the email connector in a flow and configure the same.
      • Now configure both components as follows.
    • List:
      • This will give the list of emails available in your mailbox. You can List of all emails or purifier Depends on certain options provided by the connector. We will use the List IMAP component to list the mail messages available in our mailbox.
      • Below is the flow and respect connector configuration:
        • IMAP Configuration List: While configuring this be sure to select IMAPS Connection as well as tick in Unsafe checkbox.
        • In the properties configuration, you can set a file Match with filter to do the filtering. Also, you can limit the number of emails you want to retrieve by setting Limit The value, -1 denotes all letters.
      • Now, from Postman, tap on the above app and you will see the list of emails there in your inbox. Check the output with attachments and attributes with all the details.
      • [
            {
                "inboundAttachmentNames": [],
                "exceptionPayload": null,
                "inboundPropertyNames": [],
                "outboundAttachmentNames": [],
                "payload": {
                    "attachments": {
                        "hello.txt": "Hello"
                    },
                    "body": "Test"
                },
                "outboundPropertyNames": [],
                "attributes": {
                    "headers": {
                        "Return-Path": "<givetest157@gmail.com>",
                        "Received": "",
                        "From": "givetest157@gmail.com",
                        "To": "givetest157@gmail.com",
                        "Message-ID": "",
                        "Date": "Fri, 14 Jan 2022 14:42:11 +0530 (IST)",
                        "Subject": "Test",
                        "MIME-Version": "1.0",
                        "Content-Type": "multipart/mixed;rn boundary="----=_Part_0_1243330334.1642151531229""
                    },
                    "subject": "Test",
                    "flags": {
                        "answered": false,
                        "seen": true,
                        "deleted": false,
                        "draft": false,
                        "recent": false
                    },
                    "ccAddresses": [],
                    "fromAddresses": [
                        "givetest157@gmail.com"
                    ],
                    "bccAddresses": [],
                    "toAddresses": [
                        "givetest157@gmail.com"
                    ],
                    "number": 1,
                    "sentDate": "2022-01-14T14:42:11",
                    "id": "25",
                    "replyToAddresses": [
                        "givetest157@gmail.com"
                    ],
                    "receivedDate": "2022-01-14T14:42:15"
                }
            }
        ]

    • Mark as read:

      • This will select the emails in your inbox to read. In this, we first have to bring postal number using mailing list component then pass it Identification card to Mark as read component of this activity. Below is the flow and configuration:

      • Mark as read config: You need to use the same connection configuration we created above for existing mail messages. In the properties section pass identity Received in the existing mail component output.

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

    • Mark delete:

      • Marks an incoming email as deleted. Emails marked for deletion are scheduled when the folder is closed, which means that the email is not actually deleted from the mailbox folder, but its status changes.

      • All flagged emails are deleted when folder delete or wipe is performed.

    • delete:

      • This will delete the email containing the specified email ID from your inbox.

      • Also, this will delete emails marked as deleted.

.

Leave a Comment