Back to APIs

Send emails & React emails using Resend's email service.

Using our official Resend integration

Create any tasks possible with the Resend API.

Use io.runTask() and the official SDK or fetch.

Resend integration docs

Example code using Resend

Below are some working code examples of how you can use Resend with Trigger.dev. These samples are open source and maintained by the community, you can copy and paste them into your own projects.

1
import { TriggerClient, TriggerContext, eventTrigger } from "@trigger.dev/sdk";
2
import {
3
FirstEmail,
4
MonthLaterEmail,
5
SecondEmail,
6
ThirdEmail,
7
} from "./mocks/reactEmails";
8
import { Resend } from "@trigger.dev/resend";
9
import { z } from "zod";
10
11
const resend = new Resend({
12
id: "resend",
13
apiKey: process.env.RESEND_API_KEY!,
14
});
15
16
// This job sends a drip campaign using Resend
17
client.defineJob({
18
id: "resend-drip-campaign",
19
name: "Resend: email drip campaign",
20
version: "1.0.0",
21
trigger: eventTrigger({
22
name: "send.drip.campaign",
23
schema: z.object({
24
to: z.string(),
25
// The 'from' email address must be a verified domain in your Resend account.
26
from: z.string(),
27
name: z.string(),
28
}),
29
}),
30
integrations: {
31
resend,
32
},
33
run: async (payload, io, ctx) => {
34
const email1 = {
35
text: `Hi there, welcome to our community! This is the first email we send you to help you get started.`,
36
};
37
38
// Email 1, triggered by an event
39
await io.resend.sendEmail("email-1", {
40
to: payload.to,
41
from: payload.from,
42
subject: `Thanks for joining Acme Inc`,
43
text: email1.text,
44
react: <FirstEmail name={payload.name} text={email1.text} />,
45
});
46
47
await io.wait("wait-1-day", delay(60 * 60 * 24 * 1, ctx));
48
49
const email2 = {
50
text: `Hi there, welcome to our community! This is the second email we send you to help you get started.`,
51
};
52
53
// Email 2, triggered after a day
54
await io.resend.sendEmail("email-2", {
55
to: payload.to,
56
from: payload.from,
57
subject: `Here are some tips to get started`,
58
text: email2.text,
59
react: <SecondEmail name={payload.name} text={email2.text} />,
60
});
61
62
await io.wait("wait-4-days", delay(60 * 60 * 24 * 4, ctx));
63
64
const email3 = {
65
text: `Hi there, welcome to our community! This is the third email we send you to help you get started.`,
66
};
67
68
// Email 3, triggered after 5 days
69
await io.resend.sendEmail("email-3", {
70
to: payload.to,
71
from: payload.from,
72
subject: `Do you have any questions?`,
73
text: email3.text,
74
react: <ThirdEmail name={payload.name} text={email3.text} />,
75
});
76
77
await io.wait("wait-26-days", delay(60 * 60 * 24 * 26, ctx));
78
79
const email4 = {
80
text: `This is the fourth email designed to re-engage your users after a month.`,
81
};
82
83
// Email 4, triggered after 30 days
84
await io.resend.sendEmail("email-4", {
85
to: payload.to,
86
from: payload.from,
87
subject: `How are you getting on with Acme Inc.?`,
88
text: email4.text,
89
react: <MonthLaterEmail name={payload.name} text={email4.text} />,
90
});
91
},
92
});
93
94
function delay(seconds: number, context: TriggerContext) {
95
if (context.environment.type === "DEVELOPMENT" || context.run.isTest) {
96
return 10;
97
}
98
return seconds;
99
}