Mail API
Mail API provides the ability to send emails.
Email servers
Appery.io doesn't provide an email server, instead, it provides the ability to connect to your own email server or any public email servers (e.g. Gmail, Outlook, etc.).
Method Summary
Apperyio.Mail has the following method(s):
Method | Description |
---|---|
send(params) | This method provides ability to send emails. |
The method sends email via the third-party email server.
Apperyio.Mail.send(params)
params is a JSON object with the following fields:
Parameter | Description |
---|---|
host | The host of the email server, e.g. smtp.gmail.com |
port | The post of the email server, e.g. 587 Optional, the default value is 587 |
auth | If 'true', attempts to authenticate the username. If true, then a username and password are required. Optional, the default value is "true" |
username | The username of the email server to login with. Optional if auth is "false" |
password | The 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 the 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 | The body of the message. Optional, the default value is "" |
mimeType | Mime type of 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:
- [email protected]
- "John Smith" [email protected]
- John Smith [email protected]
- [email protected], "John Smith2" [email protected]
Response
There is no response if sending the 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 the 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");