Trigger Flow When New Email Received

 

The Email connector provides a listener (called On New Email in the Studio and Design Center UIs) that polls an email folder from a mailbox for all the unread emails in it, generating a new message for each email that is found. In this way we can Trigger Flow On New Email received.

The Email Connector provides two listeners that function similarly for the IMAP and POP3 protocols

In this tutorial I will show how we can poll the email folder and trigger a flow when the new email received and read the email body and attachment content for the same

Create a project in anypoint studio

Drag and drop On New Email IMAP operation from mule palette

Configure the below parameters:

Folder: Name of the folder to poll emails default is “INBOX”

deleteAfterRetrieve: Setting the deleteAfterRetrieve parameter to true. This setting deletes each email from the mailbox folder after it has been processed so that all emails found in the next poll will be new. Both the POP3 and IMAP listeners can set the deleteAfterRetrieve parameter to true, enabling the deletion of the polled emails after processing is complete. This feature is disabled by default to avoid deleting emails by mistake

Enable Watermark: The Email connector can watermark emails when over the IMAP protocol, filtering emails based on their received date.POP3 protocol does not support watermark.

Schedule Frequency: you can set the fixed frequency to poll the folder or cron the same

Complete the connector configuration

Write the dataweave expression to fetch the email body and attachment content

%dw 2.0

output application/java 

---

{

"EmailBody":payload.body,

"EmailAttachment":payload.attachments[0]

}

Configure logger to print the payload

Deploy the project and test the same by sending a email as soon as a new received Inbox a flow will be triggered and logger will be printed, you can use email body and attachment content further

INFO 2020-04-21 14:04:08,418 [[MuleRuntime].cpuIntensive.15: [reademailfrominbox].reademailfrominboxFlow.CPU_INTENSIVE @2e4f3f5a] [event: dcf23040-83aa-11ea-8e7c-040e3cd1eac7] org.mule.runtime.core.internal.processor.LoggerMessageProcessor: {EmailBody=Test Email

<div dir=”ltr”>Test Email<div><br></div><div><br></div></div>, EmailAttachment={

“customer_id”: 1234,

“firstname”: “Scott”,

“lastname”: “daniel”,

“updateddate”: “10-09-2019”

}}

Sample application: reademailfrominbox sample application

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Mina
Mina
1 year ago

Hi
,
How we can retrieve an hyperlink present in email body? suppose we have click here as hyperlink which contains link inside it when we press it. how to retreive that link in mulesoft