Skip to content

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

js
const Mail = require('mail');
Mail.send({
  to: '[email protected]',
  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.

Common send payload fields:

  • to, subject, text, html
  • template, variables
  • attachments (base64 entries)

Practical Examples

js
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
  }
});
js
Mail.reply(
  {
    from: '[email protected]',
    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.
  • Keep template variable keys stable with mail template definitions.
  • Validate recipient email before send.