Skip to content

Email

Purpose

Send emails.

Methods

Binding name: email


Method: boolean sendEmail( final String from, final String to, final String body )

Send an email using the JavaMail API. It will return whether the email has been correctly sent or not.

Parameters:

  • from: the sender’s email address
  • to: the recipient’s email address
  • body: the email’s body content

Method: boolean sendEmail( final String from, final String to, final String body, final Map<String, String> params )

Send an email using the JavaMail API. It will return whether the email has been correctly sent or not.

Parameters:

  • from: the sender’s email address
  • to: the recipient’s email address
  • body: the email’s body content
  • params: additional parameters

Method: boolean sendEmail( final String from, final String to, final String body, final Map<String, String> params, final List<Map> mapAttachments )

Send an email using the JavaMail API. It will return whether the email has been correctly sent or not.

Parameters:

  • from: the sender’s email address
  • to: the recipient’s email address
  • body: the email’s body content
  • params: additional parameters
  • mapAttachments: attachments files

Attachments files

Zero or more attachments can be specified. Unless using the fileurl header the attachment content must be specified as bytes.

Key Description Value
name Used to identify the email body (required) body
type MIME Types (required)
filename Name for attachment
filenurl The URL of a file to attach

Additional parameters of the request

You can set the information below in the params map.

Key Description
profile.name Email profile name to use for the request
profile.appkey Email profile appKey to use for the request
replyto Reply to address
cc Courtesy copy address
bcc Blind courtesy copy address
subject The email subject

Examples

Above all, you must check that you have a default email profile set in the Email Profiles service.

Example 1

Send the message Hello from dev.b2box.com@amalto.com to toto@amalto.com.

email.sendEmail('dev.b2box.com@amalto.com', 'toto@amalto.com', 'This is email body content.')

Example 2

Same as the first example with an email’s subject.

def params = [ 'subject': 'Email Service Test' ]

email.sendEmail('dev.b2box.com@amalto.com', 'toto@amalto.com', 'This is email body content.', params)

Example 3

Same as the second example with two additional attachments: the hello.txt file and the logo.tiff logo.

def attachments = [
    [
        headers: [
            filename: 'hello.txt',
            type: 'text/plain'
        ],
        bytes: 'This is attachment content'.getBytes()
    ],
    [ 
        headers: [ fileurl: 'file:///opt/b2box5.data/logo.tiff' ] 
    ]
]

def params = [ 'subject': 'Email Service Test' ]

print email.sendEmail('dev.b2box.com@amalto.com', 'roxane.mace@amalto.com', 'This is email body content.\n', params, attachments)