Send Emails
This queue sends emails using Resend (opens in a new tab).
Prerequisites
- Sign up for an account on Resend (opens in a new tab).
- Create a new API key from your dashboard (opens in a new tab).
- Copy the generated API key and paste it in the
.env
fileRESEND_API_KEY=<your_api_key>
- Install resend package
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.