Mail related functions.
Example
var mailLib = require('/lib/xp/mail');
Methods
(static) send(message) → {boolean}
This function sends an email message using the mail server configured.
The address values can be either a simple email address (e.g. ‘name@domain.org’ ) or an address with a display name. In the latter case the email will be enclosed with angle brackets (e.g. ‘Some Name name@domain.org’ ).
The parameters to
, cc
and bcc
can be passed as a single string or as an array of strings, if there are multiple addresses
to specify.
The content-type of the email can be specified by using the contentType
parameter. See example below for
sending a message with an HTML body.
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
message |
object | JSON with the parameters. Properties
|
Returns:
True if the message was sent successfully, false otherwise.
- Type
- boolean
Examples
// Send a simple HTML mail.
var flag1 = mailLib.send({
from: 'me@enonic.com',
to: 'user@somewhere.org',
subject: 'HTML email test',
body: '<h1>HTML Email!</h1><p>You can use the contentType parameter for HTML messages.</p>',
contentType: 'text/html; charset="UTF-8"'
});
// Send a mail with attachments.
var flag2 = mailLib.send({
from: 'Sales Department <sales@enonic.com>',
to: 'user@somewhere.org',
subject: 'Email Test from Enonic XP',
cc: 'other@example.org',
bcc: ['support@enonic.com', 'other@enonic.com'],
replyTo: 'support@enonic.com',
body: 'Welcome to Enonic XP!' + '\r\n\r\n' + '- The Dev Team',
headers: {
'Disposition-Notification-To': 'me@enonic.com'
},
attachments: [
{
fileName: 'logo.png',
mimeType: 'image/png',
data: stream1,
headers: {
'Content-ID': 'logo-img'
}
},
{
fileName: 'text.txt',
data: stream2
}
]
});