Send mail from API function
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 choose the SMTP configuration and a complete message object with recipients (SendTo, SendToCc, SendToBcc), Subject, Message, IsHtml, Attachments and custom Headers.
Keep the SMTP settings — including the password — in an "SMTP configuration" document under #/ and load them with docly.getJson. Never write the SMTP password in your code.
This example sends an email through your own SMTP server, using the settings stored in the document #/My Smtp:
// #/My Smtp is an "SMTP configuration" document with SendFrom, SmtpServer,
// SmtpPort, SmtpUser, SmtpPass and SmtpSsl. It lives under #/ and is never served.
let message = {
"SendTo": "test@my-email.com",
"Subject": "Subject for message",
"Message": "Hello there",
"IsHtml": false,
"Attachments": []
};
let config = docly.getJson("#/My Smtp");
smtp.send(config, message); Important: Sending email is only possible from API functions.