Developer guide
Developer guide

Send email from server logic

Use weSystem.sendWeEmail(emailData) in an exported server function, trigger, or scheduled function. The platform handles template lookup, recipient resolution, and transaction-aware queuing. Await the result and handle failures in the calling workflow.

Direct message

await weSystem.sendWeEmail({
  to: ['recipient@example.com'],
  subject: 'Your request was received',
  text: 'We received your request.'
});

body can be used instead of text. A direct message requires both a subject and body/text. Optional fields include cc, bcc, whoIds (recipient record IDs), and whatId (related record ID). Set treatBodyAsTemplate: true only when you intend the direct content to be evaluated as a template.

Saved template

await weSystem.sendWeEmail({
  to: ['recipient@example.com'],
  templateId: 'TEMPLATE_ID',
  whatId: 'RELATED_RECORD_ID'
});

Supply templateId or direct subject plus text/body; passing both is rejected. The template path loads the saved subject and body and evaluates merge fields with whatId and whoIds where applicable. sendWeEmail supplies sendImmediate: false, so a message can be queued with the current transaction; a successful queued response is not proof of final delivery.

Source: working/platformAPI/v1.0/index.js and working/core_engines/weEmailer.js. An existing template-based call is in working/environment_modules/custom/web_to_lead/index.js.