Nimbu Developer Docs
Module Reference

mail

Send and reply to emails from Cloud Code.

What This Adds In Cloud Code

  • Transactional email sending from Cloud Code flows.
  • Template-based sends and direct text/html sends.
  • Reply helper with threading header handling.

Quick Start

const Mail = require('mail');
Mail.send({
  to: 'customer@example.com',
  subject: 'Welcome',
  text: 'Welcome to our platform.'
});

API

FunctionParamsReturnsNotes
send(params)mail payloadboolean | objectRequires to; non-template mail also requires subject and text.
reply(params, rawHeaders, options)payload + raw header stringboolean | objectBuilds reply/thread metadata automatically. options supports fallback_to and fallback_subject.

send payload fields:

FieldTypeNotes
tostring or string[]Required.
fromstringDefaults to the site's email address.
cc, bccstring or string[]Optional.
replyTostring or string[]Defaults to from.
inReplyTo, referencesstring or string[]Message ids for threading. reply() fills these in.
subject, text, htmlstringRequired for non-template mail: subject and text. html is optional.
template, variablesstring, objectSend a notification template from the site instead of subject/text.
headersobjectCustom X- headers, see below.
attachmentsobject or array{ 'file.pdf': '<base64>' } or [{ filename, content }], content base64-encoded.

Addresses accept display names: 'Support <support@example.com>'.

Custom headers

headers only adds your own X- headers:

Mail.send({
  to: 'customer@example.com',
  subject: 'Your export',
  text: 'Your export is ready.',
  headers: { 'X-Export-Id': exportId }
});

These are dropped without an error, and the mail is still sent:

  • Names that don't start with X- (any case).
  • Names starting with a reserved prefix: X-Nimbu-, X-Original-, X-TEM-, X-Scw-, X-Scaleway-.
  • Values containing a line break (CR or LF).

Practical Examples

const Mail = require('mail');

Mail.send({
  to: request.params.email,
  template: 'order-confirmation',
  variables: {
    first_name: request.params.first_name,
    order_number: request.params.order_number
  }
});
Mail.reply(
  {
    from: 'support@example.com',
    text: request.params.reply_text
  },
  request.params.raw_headers,
  {
    fallback_to: request.params.to,
    fallback_subject: 'Re: Support'
  }
);

Failure Modes & Gotchas

  • Missing required fields can return falsey result instead of hard crash.
  • A template that doesn't exist on the site sends nothing and logs an error.
  • Attachments with a file type the email provider refuses are dropped and logged; the mail is still sent.
  • Keep template variable keys stable with mail template definitions.
  • Validate recipient email before send.

On this page