Skip to content

Martini Invoking Services via a Email Trigger

The Email trigger in Martini enables applications to react to email messages received on a mail server. Martini checks the configured email account periodically and triggers a specified [service][service] upon receiving new, unread emails.

Properties

General Configuration

Refer to the general trigger configuration documentation for common properties applicable to all triggers.

Email-specific Configuration

Property Default Description
Host (required) The email server to connect to.
Port 993 The server port number.
Username (required) The email address used to login.
Password (required) The password used for login.
Polling Interval 1 The interval in seconds for checking the inbox.
Use SSL true Whether the connection uses SSL.
Type IMAP The email protocol used (IMAP or POP3).
Delete email on receive false If the email should be deleted after service invocation.
Send Service response as reply false If the service's output is used as a reply.
Send reply on error false If exceptions thrown by the service are sent back as a reply.

Reply Properties

When replying to emails, additional properties are required:

Property Default Description
Host (required) The email server for sending replies.
Port 465 The server port for SMTP.
Username (required) The email address for sending replies.
Password (required) The password for the reply email account.
From (required) The sender's email address. Uses 'Username' if not provided.
SSL/TLS true Whether the connection for sending emails uses SSL/TLS.

Service

Email-specific Parameters

Name Type Description
message [javax.mail.Message][javadoc-javax-mail-Message] The email message that triggered the trigger.
to [javax.mail.Address[]][javadoc-javax-mail-Address] The recipients of the email.
cc [javax.mail.Address[]][javadoc-javax-mail-Address] The CC'd addresses.
bcc [javax.mail.Address[]][javadoc-javax-mail-Address] The BCC'd addresses.
from [javax.mail.Address[]][javadoc-javax-mail-Address] The sender's address.
fromAddress java.lang.String The first address in 'from'.
replyTo [javax.mail.Address[]][javadoc-javax-mail-Address] Addresses for replies.
subject java.lang.String The email's subject.
headers java.util.List<[javax.mail.Header][javadoc-javax-mail-Header]> The email's headers.

Additional variables are available if the message type is MimeMessage.

Examples

Groovy Script as Service

Here's a Groovy script example that prints available variables in the context when the Email trigger is activated:

1
2
3
4
5
6
7
[
    'properties',
    'parameters',
    // List of other variables
].each { 
    println "$it\t : " + this[it]   
}

When the trigger is activated by an incoming email, the console prints the variables and their values, helping to debug and understand the available data.

Groovy Method as Service

The following Groovy method logs the content and name of each attachment from the received email:

1
2
3
4
5
6
7
8
class Reader {

    def readAttachments(def attachments) {
        attachments.each {
            "Attachment ${it.name} has content ${it.inputStream.text}".info()
        }
    }
}

This method iterates over the attachments variable, logging the details of each attachment, useful for processing email content in a service.