Send mail from API function Last updated: 24. Jun 2026
Follow this example to send email from your application.
sendEmail(file, template, receiver, subject, message)
Use this function to generate a document from a built-in template and send it by email. Note: this is not just a plain text email — the function renders output (PDF, DOCX, HTML, etc.) from a template defined in the document's schema, and attaches/sends that generated file.
Built-in templates are defined in the document's schema. A schema describes the structure and editor of a document and can include HTML, DOCX or XLSX templates that merge the document's data into a visual representation. To produce a PDF, create an HTML or DOCX template and add ".pdf" to the template name — for example "Receipt.html.pdf". Read more about schemas and templates here: https://developers.docly.net/Schemas/About-schemas
This example will send a document by email to test@docly.net:
docly.sendEmail(filepath, "Receipt.html.pdf", "test@docly.net", "Subject here", "Message body here in text\nNew line\nThanks!"); For line breaks in text use \n
Important: Sending email is only possible from API functions.
sendForm(form, subject, [options])
Use this function to send a submitted form by email from an API function. Example sending a posted form from API function:
let form = {
"Message": "This is just an example",
"Link": "https://docly.org"
};
docly.sendForm(form, "Contact form", { sendTo: "test@docly.net" }); smtp.send(config, message)
Use this function when you need full control over the email and want to send through your own SMTP server. Unlike sendEmail and sendForm, smtp.send lets you specify the SMTP configuration (server, port, user, password, SSL) and a complete message object with recipients (SendTo, SendToCc, SendToBcc), ReplyTo, Subject, Message, IsHtml, Attachments and custom Headers.
The config can be supplied inline as an object, or loaded from an "SMTP configuration" file using docly.getFile("#/My Smtp").
This example sends an email with an attachment through your own SMTP server:
let config = {
"SendFrom": "no-reply@your-domain-here.com",
"SmtpServer": "your-smtp-server-here",
"SmtpPort": 587,
"SmtpUser": "login user",
"SmtpPass": "login password",
"SmtpSsl": true
};
let message = {
"SendTo": "test@my-email.com",
"Subject": "Subject for message",
"Message": "Hello there",
"IsHtml": false,
"Attachments": []
};
smtp.send(config, message); Important: Sending email is only possible from API functions.