Skip to Content

Email

ctx.EMAIL sends email. Mail comes from your verified domain when you have one, and replies come back to this loop’s agent. To verify a domain and give the agent an inbound address, see WhatsApp and email.

Email has to be on for the loop under Settings → Channels. Otherwise the call throws Email is not on for this loop. Turn it on under Settings → Channels.

Send one

await ctx.EMAIL.send({ to: "thandi@example.com", subject: "Your scan results", text: "Your results are ready.", });

subject and text are required. Add html for a formatted version.

Send several

await ctx.EMAIL.send({ messages: [ { to: "thandi@example.com", subject: "Your scan results", text: "Your results are ready." }, { to: "sipho@example.com", subject: "Your scan results", text: "Your results are ready." }, ], });

Pass either to, subject, and text, or messages, not both.

What comes back

{ ids }, one per email sent. When Bulk messages needs approval in Controls and the send has more than one recipient, you get { status: "pending_approval", approvalId, message } instead, and the emails go out when someone approves them.

Example: email the report

import { workflow } from "@loops/sdk"; type ScanRequest = { email: string }; export const emailReportWorkflow = workflow<ScanRequest>({ id: "email-report", execute: async ({ step, event }) => { await step.do("Create the scan", ({ ctx }) => ctx.FACIAL_SCAN.create({})); const scan = await step.waitForScan({ timeout: "30 minutes" }); await step.do("Email the report", async ({ ctx }) => { await ctx.EMAIL.send({ to: event.body.email, subject: "Your scan report", text: `Your report is ready: ${await scan.pdfUrl()}`, }); }); }, });
Last updated on