smtp.send(config, message)
Send email by SMTP.
Parameters
configobject | stringrequiredConfiguration for the SMTP server to send the message through: an object with SendFrom, SmtpServer, SmtpPort, SmtpUser, SmtpPass and SmtpSsl — or the path to an "SMTP configuration" document, such as "#/My Smtp". A path reads the values of that document, the same as docly.getJson("#/My Smtp").
messageobjectrequiredMessage object with SendTo, SendToCc, SendToBcc, ReplyTo, Subject, Message, IsHtml, Attachments and Headers.
Returns
An object { Success: true, MessageId } when the message is sent. Throws an error if the configuration is incomplete (SmtpServer, SmtpPort and SmtpSsl are required) or sending fails.
SmtpSsl means STARTTLS: true connects in plain text and upgrades with STARTTLS (port 587). Implicit TLS on port 465 is not supported. Set SmtpOauth2: true to log in with an OAuth2 access token in SmtpPass.
SendFrom on the message overrides the one in the configuration. ReplyTo is used since 15 October 2026.
Keep the configuration — including the password — in an "SMTP configuration" document under #/ and pass its path as config — smtp.send("#/My Smtp", message) — instead of writing it in code. No platform mail limit applies: the mail goes through your own server.
Example
// Use the default Docly SMTP structure:
let config = {
"SendTo": "", // default value, used only if not specified in message object
"SendToCc": "", // default value, used only if not specified in message object
"SendToBcc": "", // default value, used only if not specified in message object
"SendFrom": "no-reply@your-domain-here.com", // Required; the message can override it
"SmtpServer": "your-smtp-server-here",
"SmtpPort": 587,
"SmtpUser": "login user",
"SmtpPass": "login password",
"SmtpSsl": true
};
// Better: keep it in an "SMTP configuration" document under #/ and pass its path:
// let config = "#/My Smtp";
// Use the default Docly Message structure:
let message = {
"SendTo": "test@my-email.com",
"SendToCc": "",
"SendToBcc": "",
"ReplyTo" : "", // Optional
"Subject" : "Subject for message",
"Message" : "Hello there",
"IsHtml" : false,
"Attachments" : [],
"Headers": { // Optional, add any desired headers for the email
"In-Reply-To": "....",
// etc
}
};
let filedata = []; // TODO: array of bytes or base64 encoded string
// Add one or more files to message
message.Attachments.push({ "Filename" : "Test file.pdf", "Data" : filedata });
// Send the message through server
smtp.send(config, message);