The mail
service facilitates the sending of e-mail messages via SMTP.
The properties of mail.smtp
must be set before the mail.send
function can be used.
Example:
mail.smtp.server = "smtp.gmail.com";
mail.smtp.port = 587;
mail.smtp.userName = "my.account@gmail.com";
mail.smtp.password = "my.password";
mail.smtp.enableSSL = true;
mail.send("sender@test.com", "recipient@test.com", "Test message", "This is a test");
The above sends a plain-text message. Rich-text messages may be sent as follows:
mail.send("sender@test.com", "recipient@test.com", "Test message", {
textPlain: "This is a test",
textHtml: "No, <b>this</b> is a test"
});
Members
(static) smtp
SMTP server configuration
Properties:
Name | Type | Description |
---|---|---|
server |
String | Host-name or IP address of SMTP server. |
port |
String | Port of SMTP server. |
userName |
String | User-name of account on SMTP server. |
password |
String | Password of account on SMTP server. |
enableSSL |
Boolean | Set to true if using SSL. |
Methods
(static) send(from, to, subjectopt, bodyopt, attachmentsopt, headersopt)
Sends an e-mail message via SMTP as configured by the smtp
object of this
class. The body of the message may be a simple string (plain-text) or an object
defining a multi-part MIME encoded message (see below). Attachments from the
CompleteFTP virtual file-system may also be added.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
from |
String | From address |
|
to |
String | To address |
|
subject |
String |
<optional> |
Subject of the message |
body |
Object |
<optional> |
Body of the message. This may either be a simple string or an object. If it's an object then a MIME multi-part message will be generated. One part will be generated for each property. The MIME type of the part is determined by the name of the property, e.g. the property "textPlain" becomes the type "text/plain", and "textHtml" becomes "text/html". The content of a part is the stringified value of the corresponding property value. |
attachments |
Array.<String> |
<optional> |
Array of strings containing the paths in the virtual file-system of the files to be attached. |
headers |
Object |
<optional> |
Name-value pairs of header variables. |