This workshop demonstrates how emails can be read from an inbox and processed
via IMAP. This is done by creating a process with an IMAP event source
an IMAP event handler. The email is written to a data group via a Groovy
script action.
Please note that emails in HTML can lead to security flaws
(by allowing JavaScript to be infiltrated, for example).
2. Example application
Download the example application here.
Import the downloaded file "advanced-techniques-mail-connection-with-imap.zip"
and select the application and the process it contains. Then switch to the
Processes module,
open the process "Advanced Techniques - Mail connection with IMAP"
and activate it.
The following functionalities are covered by the application:
Identify the sender
Identify the recipient (including CC)
Identify the arrival time
Identify the subject
Convert email's content from HTML to plaint text
Convert email's content from plaint text to HTML
Present the email in HTML
Present the email in plaint text
Identify attachments
Identify / Separate inline attachments
Add the email to an Intrexx data group
Add the attachments to an Intrexx data group
The email's format (HTML / Plain text) can be modified on the
"Settings" page in the application.
First of all, the code imports the class, creates a new instance and
parses the email.
The "pm" object provides us with a variety of methods to, for example,
get the mail's subject, content (as HTML or plain text), sender or attachments.
Some examples:
def strFrom = pm.sender.address //Get sender
def strTo = TextUtil.listToString(pm.recipients*.address) //Get recipient(s)
def strCC = TextUtil.listToString(pm.recipientsCc*.address) //Get recipient(s) in CC
def attachments = pm.getAttachments() //Get attachments
def strHTMLContent = pm.getRawHTMLContent() //Get content as HTML
def strPlainTextContent = pm.getPlainTextContent() //Get content as plain text
Subsequently, we can add the information and attachments from the email to
Intrexx data groups using INSERT statements.