Notification Triggers and Actions - Mail Trigger
Monitors an email server for incoming mail and fires when email arrives.
Properties
Server
Sets the hostname of the email server.
Polling Delay
Sets a time expression that specifies how long the mail trigger waits to poll the mail server for new email messages.
Port
Sets the mail server port.
Username & Password
Sets the credentials to access the mail server
Protocol
Sets the mail protocol used to communicate with the mail server. It can be either IMAP or POP3
Delete Processed Message
Sets whether a processed email is automatically deleted after control returns to the mail trigger. Note that when using the POP3 protocol, the JavaMail implementation does not appear to allow messages to be deleted.
IMAP Folder
Sets the name of the IMAP folder that is checked for email messages.
IMAP Folder Copy Destination
Sets the name of an IMAP folder, if any, to which a processed email is copied when the mail trigger fires.
Results
The Mail Trigger returns its results in the flow context variable “result”. These results include information about the mail subject and its body, the addresses associated with the mail, and attachments for the mail. You can access the Mail Trigger results from the following fields:
Flow Context Variable | Field | Java Type | Description | Prescript / Postscript Example |
---|---|---|---|---|
RESULT | attachments | List<MailTrigger.MailAttachment> | The file attachments in the mail message. See Using MailAttachments below for more information. | List attachments = flowContext.get("RESULT").attachments; for (MailAttachment attachment : attachments) {byte[] attachBody = attachment.body; System.out.println(attachBody); } |
RESULT | body | String | The body of the mail message. | String body = flowContext.get("RESULT").body; System.out.println("Message body: " + body); |
RESULT | cc_addresses | List<String> | The carbon copy recipients of the mail message. | List cc_addresses = flowContext.get("RESULT").cc_addresses; for (String cc_address : cc_addresses) { System.out.println("CC: " + cc_address); } |
RESULT | content_type | flux.notification.MailContentType | The content type of the mail message. | MailContentType contentType = flowContext.get("RESULT").content_type; System.out.println("Content type: " + contentType); |
RESULT | from_addresses | List<String> | The senders of the mail message. | List from_addresses = flowContext.get("RESULT").from_addresses; for (String from_address : from_addresses) { System.out.println("From: " + from_address); } |
RESULT | reply_to_addresses | List<String> | The reply-to addresses of the mail message. | List reply_to_addresses = flowContext.get("RESULT").reply_to_addresses; for (String reply_to_address : reply_to_addresses) { System.out.println("Reply to: " + reply_to_address); } |
RESULT | sent_date | Date | The date the mail message was sent. | Date sentDate = flowContext.get("RESULT").sent_date; System.out.println("Sent date: " + sentDate); |
RESULT | size | int | The size of the mail message. | int size = flowContext.get("RESULT").size; System.out.println("Size: " + size); |
RESULT | status_flags | javax.mail.Flags | Status flags for the email message. | Flags statusFlags = flowContext.get("RESULT").status_flags; if (flags.getSystemFlags().contains(Flags.Flag.DELETED)) { System.out.println("Message was deleted"); } |
RESULT | subject | String | The subject of the mail message. | String subject = flowContext.get("RESULT").subject; System.out.println("Subject: " + subject); |
RESULT | to_addresses | List<String> | The recipients of the mail message. | List to_addresses = flowContext.get("RESULT").to_addresses; for (String to_address : to_addresses) { System.out.println("To: " + to_address); } |
Passing Results with a Runtime Data Map
You can use a Runtime Data Map to copy one of the result fields into a new variable (for future reference or to reuse the data later in the workflow).
To copy a result field, you can use a data map like:
Using Mail Attachments
If a message picked up by a mail trigger contains attachments, they are returned as MailAttachment objects. These objects have two fields:
Field | Description | Prescript / Postscript Example |
---|---|---|
body | A byte[] containing the body (content) of the attachment. | List attachments = flowContext.get("RESULT").attachments; for (MailAttachment attachment : attachments) { byte[] attachBody = attachment.body; System.out.println(attachBody); } |
filename | The filename of the attachment. | List attachments = flowContext.get("RESULT").attachments; for (MailAttachment attachment : attachments) { String filename = attachment.filename; System.out.println(filename); } |
You can also access the attachments through runtime data mapping. For example, you could use the following data map to pass the attachments from the mail trigger into a for each collection element action:
Once the For Each Collection Element Action adds the next attachment to the flow context, you can access its fields with another data map: