Docly Developers
Function API only Updated 18 Oct 2026

SmtpClientMk(config)

Creates an SMTP client, connects and logs in: new docly.SmtpClientMk(config). Use it to send several messages over one connection. Call disconnect() when you are done.

Methods:

  • send(message) — sends a message and returns { Success: true, MessageId }. Throws if sending fails.
  • disconnect() — closes the connection. Returns true, or false when it was already closed.

Unlike smtp.send, the SendTo/SendFrom defaults in the configuration are not used: each message must have its own SendTo and SendFrom.

Parameters

configobject | stringrequired

SMTP configuration, the same as for smtp.send: SmtpServer, SmtpPort and SmtpSsl are required; SmtpUser and SmtpPass log in. SmtpSsl means STARTTLS. Set SmtpOauth2: true to log in with an OAuth2 access token in SmtpPass. Or pass the path to an "SMTP configuration" document, such as "#/My Smtp".

Returns

The client object with the methods above. Throws if the configuration is incomplete or the connection or login fails. The message object is the same as for smtp.send: SendTo, SendToCc, SendToBcc, SendFrom, ReplyTo, Subject, Message, IsHtml, Attachments, Headers and MessageId.

Example

Normal JavaScript, running in the browser or on the Docly™ server.
let config = docly.getJson("#/Config").Smtp;   // keep credentials out of the code
let smtp = new docly.SmtpClientMk(config);

try {
    for (let to of ["a@example.com", "b@example.com"]) {
        smtp.send({
            "SendTo" : to,
            "SendFrom" : "no-reply@example.com",
            "Subject" : "Hello",
            "Message" : "Hello there",
            "IsHtml" : false
        });
    }
} finally {
    smtp.disconnect();
}