Purpose¶
Send emails.
Methods¶
Binding name: p6.email
Method: boolean sendEmail( final String from, final String to, final String plainBody )
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 addressto
: the recipient’s email addressplainBody
: the email’s body content as plain text
Method: boolean sendHtmlEmail( final String from, final String to, final String htmlBody )
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 addressto
: the recipient’s email addresshtmlBody
: the email’s body content as html
Method: boolean sendEmail( final String from, final String to, final String plainBody, 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 addressto
: the recipient’s email addressplainBody
: the email’s body content as plain textparams
: additional parameters
Method: boolean sendHtmlEmail( final String from, final String to, final String htmlBody, 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 addressto
: the recipient’s email addresshtmlBody
: the email’s body content as htmlparams
: additional parameters
Method: boolean sendEmail( final String from, final String to, final String plainBody, 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 addressto
: the recipient’s email addressplainBody
: the email’s body content as plain textparams
: additional parametersmapAttachments
: attachments files
Method: boolean sendHtmlEmail( final String from, final String to, final String htmlBody, 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 addressto
: the recipient’s email addresshtmlBody
: the email’s body content as htmlparams
: additional parametersmapAttachments
: attachments files
Method: boolean sendEmail( final String from, final String to, final String plainBody, final String htmlBody, final Map<String, String> params, final List<Map> mapAttachments )
Send a multipart email containing a plain text and html body using the JavaMail API. It will return whether the email has been correctly sent or not.
Parameters:
from
: the sender’s email addressto
: the recipient’s email addressplainBody
: the email’s body content as plain texthtmlBody
: the email’s body content as html textparams
: additional parametersmapAttachments
: 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.
p6.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' ] p6.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 p6.email.sendEmail('dev.b2box.com@amalto.com', 'roxane.mace@amalto.com', 'This is email body content.\n', params, attachments)
Example 4
Send a multipat email
def params = [ ] def attachments = [ ] p6.email.sendEmail('dev.b2box.com@amalto.com', 'toto@amalto.com', 'This is plain text email body content.', 'This is <b>html email</b> body content.', params, attachments)