Skip to main content

Mail

sendMail

Sends an e-mail with the given data.

sendMail(mailData);
sendMail(mailData, outboundEmailConfiguration);

The mailData parameter can contain the following properties:

  • to: (required) string containing the e-mail address(es) of the recipient(s). Specify multiple addresses by separating them with a comma.
  • cc: string containing the e-mail address(es) of the CC recipient(s).
  • bcc: string containing the e-mail address(es) of the BCC recipient(s).
  • subject: (required) string with the subject of the e-mail.
  • body: (required) object containing the body of the e-mail, which may contain either or both of the following properties:
    • html: the HTML body of the e-mail.
    • text: the text body of the e-mail.
  • attachments: array of objects containing the attachments of the e-mail. Each attachment object must contain the following properties:
    • filename: The name of the file to be attached.
    • content: The content of the file to be attached as a string or a Buffer.
    • contentType: (optional) The MIME type of the file.

Note: when sending an e-mail through Microsoft Graph, the text property is ignored when the html property is also present.

The optional outboundEmailConfiguration parameter is used as follows:

  • If the name of an outbound email configuration is specified in the outboundEmailConfiguration parameter, and the configuration is enabled, it uses that configuration to send the e-mail.
  • Otherwise, it uses the enabled outbound email configuration marked as default, if the environment has one.
  • Otherwise, an exception is thrown.

Example 1: Send a simple e-mail

const mailData = {
to: "mail@company.com",
cc: "mail@company.com", // optional
bcc: "mail@company.com", // optional
subject: "Mail Subject",
body: {
text: "Mail Body Text",
},
};

sendMail(mailData, "my-outbound-email-configuration");

Example 2: Send an e-mail generated from a template

// The template 'my-template' has defined the mail subject and HTML body.
const mailData = createTemplateHTMLMail("my-template");

// add recipients
mailData.to = "mail@company.com";
mailData.cc = "mail@company.com"; // optional
mailData.bcc = "mail@company.com"; // optional

sendMail(mailData, "my-outbound-email-configuration");

Example 3: Send an e-mail using the default outbound email configuration

sendMail({
to: request.requested_by,
subject: "Mail Subject",
body: {
text: "Mail Body Text",
},
});

Example 4: Send an e-mail with an attachment

const docDefinition = {
content: "Very important document",
};

const pdfBuffer = create_pdf(docDefinition);

const attachment = {
filename: "document.pdf",
content: pdfBuffer,
};

const subject = `Your document`;
const text = `See attached PDF document.`;

const mailData = {
to: "user@test.com",
subject: subject,
body: {
text: text,
},
attachments: [attachment],
};

sendMail(mailData);