Skip to content

Send Emails from Your Application

In this tutorial, you’ll send emails from your application using a configured mail server.

You’ll build and send an email dynamically, including recipients, subject, content, and optional attachments.

This pattern is commonly used in workflows to send notifications, confirmations, or requests.


By the end of this tutorial, you will:

  • Configure email sending using a mail server
  • Build an email object dynamically
  • Send emails from your application
  • Control recipients, subject, and content
  • Integrate email sending into workflows

  • A configured mail server connection (e.g. emailConfig)
  • Access to a workflow or script where the email will be sent
  • Basic understanding of objects and functions

Ensure you have a mail configuration set up (from the previous tutorial).

This configuration contains:

  • Mail server host
  • Credentials
  • Default sender

Create an email object with the required fields:

const mail = {
to: "recipient@example.com",
subject: "Your request has been received",
html: "<p>Thank you for your request.</p>"
};

You can also include:

  • cc
  • bcc
  • replyTo
  • attachments

Use the built-in mail function to send the email:

await sys.mail.sendMail($config.emailConfig, mail);

This sends the email using your configured mail server.


You can generate content dynamically:

const mail = {
to: emailRecord.from,
subject: `Request received: ${emailRecord.subject}`,
html: `<p>We received your request and will process it shortly.</p>`
};

This allows you to:

  • Personalize emails
  • Use data from workflows
  • Generate context-aware responses

Attach files to your email:

const mail = {
to: "recipient@example.com",
subject: "Document attached",
html: "<p>Please see attached.</p>",
attachments: [
{
fileName: "document.pdf",
data: fileBuffer
}
]
};

Section titled “Step 6: Use mock recipients (recommended for testing)”

To prevent sending real emails during development, enable mock recipients in your configuration.

This ensures all emails are redirected to test addresses.


You can now send emails from your application.

This allows you to:

  • Notify users
  • Respond to incoming requests
  • Integrate communication into workflows

The system uses your configured mail server to send emails.

When sendMail is called:

  1. The mail object is constructed
  2. The mail server connection is used
  3. The email is sent to the specified recipients

  • Combine with incoming email processing
  • Send workflow notifications
  • Generate email content using AI
  • Build automated communication flows

  • Sending Emails
  • Email Triggers
  • Workflow Fundamentals