Sending Messages
To send e-mails you must have a mail config key in place or to create a plain object as explained in the Settings section.
require("inpaas.mail.service").getSender()
.withConfig("inpaas.scheduler.notifications")
.send({
"from": "[email protected]",
"to": "[email protected]",
"subject": "Um Teste de Envio 1",
"text": "Olá Mundo!"
})
.then(function(data) {
// the sent message is available in the promise
}).catch(function(e) {
// the exception thrown is available
});
Message
You can send messages using the send method. The message may have the following attributes(the itens in bold are required):
from
A string containing the sender e-mail address.
to
A string containing the recipients e-mail address. You can send a message to multiple recipients using an Array of Strings or a semicolon separated string.
cc
A string containing the recipients e-mail address. You can send a message to multiple recipients using an Array of Strings or a semicolon separated string.
bcc
A string containing the recipients e-mail address. You can send a message to multiple recipients using an Array of Strings or a semicolon separated string.
subject
A string containing the message subject.
headers
A plain object (key-value pair) containing header names and values to be sent with the message.
attachments
A list containing message attachments. The attachments may be a FileData object returned from the File Service.
html, body or text
You can provide a body, html or text attribute. Should you provide a body attribute you must also provide the contentType.
contentType
This is the contentType of the message. If you provide a html or text attribute, this will be automatically filled. If you provide a body attribute the contentType is required.
Promise.then(resolve, reject)
The send method returns a Promise. Check out Promise Documentation Online for further information.
The resolve future is invoked with the message as an argument. The reject future is invoked with the exception.
.then(function afterSend(message) {
// your message is available in the 'message' parameter
}, function onError(e) {
// if any error occurs while sending the message,
// you will be notified in the 'catch' part of the Promise
logging.error("catch: {}", e, e);
});
Promises and Async
Keep in mind that Promises are executed in async mode. You can use the "wait()" method to wait for the Promise to be full-filled before your code can continue.
Updated less than a minute ago