Send Emails

This queue sends emails using Resend (opens in a new tab).

Prerequisites

npm install resend

Implementation

queues/email.ts
import { queue, z } from "@turboq/sdk";
import { Resend } from "resend";
 
export default queue("Send Emails")
  .input(
    z.object({
      from: z.string(),
      to: z.array(z.string()),
      subject: z.string(),
      html: z.string(),
    })
  )
  .step("send", async ({ input }) => {
    const resend = new Resend(process.env.RESEND_API_KEY);
    const result = await resend.emails.send(input);
 
    if (result.error) {
      throw new Error(result.error.message);
    }
 
    return result.data;
  });

Usage

To use this queue from other queues, check out the docs on child jobs.