smtp.send(config, message) Last updated: 27. May 2024

API only function

Send email by SMTP.

Parameters

Name Type Description
config object / path Configuration for SMTP server to send message through.
OR filepath to "SMTP configuration" file.
message object Message object with to, cc, bcc, subject, message and isHtml.

Returns

True (boolean) or may throw a validation error.

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
// 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, always used
   "SmtpServer": "your-smtp-server-here",
   "SmtpPort": 587,
   "SmtpUser": "login user",
   "SmtpPass": "login password",
   "SmtpSsl": true
};

// Or load it from a file:
// let config = docly.getFile("#/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);