Smtp adapter
The SMTP Adapter allows you to send an e-mail; this is particularly interesting to add - for instance - password reset functionality in the workflow.
Prerequisites
The adapter requires an SMTP-server.
Configuration
AdapterUniqueID
Unique name assigned to this adapter; the name is used to reference the adapter in the workflow. The ID has following requirements:
START with a letter or _ (underscore)
FOLLOWED by a combination of following characters: Letter, Number, '.' (dot), '-' (dash), '_' (underscore)
Port Port of your mailserver to send mail to (mandatory)
JndiName The JNDI name of the mail session if you use a mail server application (mandatory if you use an application)
Host Host address of your mailserver (mandatory)
Password Password used to authenticate
User Username to authenticate
Workflow Settings
A request for the adapter is prepared by specifying the following properties/scripts in the adapter activity:
Input Property: the variable containing the instructions the adapter have to execute
Output Property: the variable the adapter will store the response in after execution
Before Adapter Script: script that will be executed before calling the adapter
After Adapter Script: script that will be executed after the adapter fulfilled its task
Request - API
smtpRequest
function sendEmail(workItem) {
var mailoptions = {
from: 'from@example.com',
to: 'to@example.com',
bcc: 'bcc@example.com',
subject: 'sample subject',
html: 'sample message'
};
workItem.mailInput = tb.smtpRequest(mailoptions);
}
where "mailoptions" contain:
To: Recipient of the mail
From: Sender of the mail
CC: Recipients in carbon copy
BCC: Recipients in blind carboncopy
Subject: Subject of the mail
Body: Plain text body
Html : Html body
Parts: a list of attachments
Response - API
Common Properties
The response API can be applied to the variable specified in the "output property" (see "Workflow Settings"): to verify whether the action performed by the adapter was successful, to query for the data returned by the adapter.
All responses have four properties in common:
status Status flag indicating whether the response is ok (0) or not (1).
substatus Response specific number indicating what the problem was, eg. http status code
message Response specific message in case there was a problem (can be null)
rc Return Code, a human readable code based on the substatus
function checkEmail(workItem) {
var response = workItem.mailOutput;
if (response.status === 0) {
// mail is sent
}
else {
// error occured
}
}
Response Codes
If all is ok, the status is zero, for non-zero statusses you can find the description below.
1 Invalid Address
2 No such provider The application server doesn't support an SMTP provider
3 Messaging problem