send

Apperyio.Mail.send(params)

Sends email via the third-party email server.

Parameters Summary

This method has the following parameters:

Parameters

Description

params

params is JSON object with such fields:

host - host of email server, e.g. smtp.gmail.com
port - post of email server, e.g. 587
Optional, the default value is 587
auth - if true, attempts to authenticate the username. If true, then username and password are required. Optional, the default value is "true"
username - username of the email server to login with. Optional if auth is "false"
password - password of the email server to login with. Optional if auth is "false"
tls - if true, switches the connection to a TLS-protected connection before issuing any login command. Optional, the default value is "true"
from - email address of author of the email. Corresponds to the From field in rfc2822. Optional if "sender" is set
sender - specifies the mailbox of the agent responsible for the actual transmission of the message. Corresponds to the Sender field in rfc2822. Optional if "from" is set
replyTo - indicates the mailbox(es) to which the author of the message suggests that replies be sent. Corresponds to the Reply-To field in rfc2822. Optional, the default value is ""
to - address(es) of the primary recipient(s) of the message. Corresponds to the To field in rfc2822
cc - addresses of others who are to receive the message, though the content of the message may not be directed at them. Corresponds to the Cc field in rfc2822
bcc - addresses of recipients of the message whose addresses are not to be revealed to other recipients of the message. Corresponds to the Bcc field in rfc2822
subject - a short string that identifies the topic of the message. Corresponds to the Subject field in rfc2822. Optional, the default value is "".
content - body of the message. Optional, default value is "".
mimeType - mime type of the content. Optional, the default value is "text/plain; charset=UTF-8".
date - long, is a timestamp that specifies the date and time at which the creator of the message indicated that the message was complete and ready to enter the mail delivery system. Optional, the default value is set as system time. E.g.: 1591074040113 for "2020-06-01T22:00:40-07:00"
headers - dictionary of custom fields. Any value-added here will be added after all previous fields or replaces the fields if rfc2822 says that it should be only one value. The value in the dictionary could be either String or Array of strings e.g.:
"headers": { "header1": "value1", "header2": ["value1", "value2"] }

📘

Email addresses

Email addresses should comply with the rfc2822 specification. Correct values:

Response

There is no response if sending of email was successful.

Examples

Simplest gmail example without content

The following example sends empty email from [email protected] to [email protected] using Gmail server:

var result;
try {
    Apperyio.Mail.send({
        "host": 'smtp.gmail.com',
        "to": '[email protected]',
        "auth": true,
        "tls": true,
        "username": "[email protected]",
        "password": "qwnbctostinpwtej"
    });
    result = "success";
} catch (e) {
    result = JSON.stringify(e);
}
Apperyio.response.success(result, "application/json");
Gmail example with content

The following example sends an email with subject and content:

var result;
try {
    Apperyio.Mail.send({
        "host": 'smtp.gmail.com',
        "to": '[email protected]',
        "auth": true,
        "tls": true,
        "username": "[email protected]",
        "password": "qwnbctostinpwtej",
        "content": 'Hello World',
        "mimeType": "text/plain"
    });
    result = "success";
} catch (e) {
    result = JSON.stringify(e);
}
Apperyio.response.success(result, "application/json");
Full Gmail example

This example uses all the abilities of Appery.io email sending API:

var result;
try {
    Apperyio.Mail.send({
        "host": 'smtp.gmail.com',
        "from": '"John Smith" <[email protected]>',
        "to": '"John1" <[email protected]>',
        "auth": true,
        "tls": true,
        "username": "[email protected]",
        "password": "qwnbctostinpwtej",
        "cc": '"John2" <[email protected]>, "John3" <[email protected]>',
        "bcc": '"John4" <[email protected]>',
        "subject": 'subject',
        "replyTo": '"John Smith" <[email protected]>',
        "content": '<h1>Hello World<h1>',
        "mimeType": "text/html",
        "date": 1591074040113,
        "headers": {
            "test": "test",
            "test2": ["test", "test2"]
        }
    });
    result = "success";
} catch (e) {
    result = JSON.stringify(e);
}
Apperyio.response.success(result, "application/json");