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, eventTrigger } from "@trigger.dev/sdk";
2
import { Resend } from "@trigger.dev/resend";
3
import { z } from "zod";
4
5
// react-email imports
6
import { Html } from "@react-email/html";
7
import { Head } from "@react-email/head";
8
import { Text } from "@react-email/text";
9
import { Button } from "@react-email/button";
10
import { Section } from "@react-email/section";
11
import { Preview } from "@react-email/preview";
12
import { Container } from "@react-email/container";
13
14
const resend = new Resend({
15
id: "resend",
16
apiKey: process.env.RESEND_API_KEY!,
17
});
18
19
// Email styling
20
const container = {
21
width: "480px",
22
margin: "0 auto",
23
padding: "20px 0 48px",
24
};
25
26
const title = {
27
fontSize: "24px",
28
lineHeight: 1.25,
29
};
30
31
const section = {
32
padding: "24px",
33
border: "solid 1px #dedede",
34
borderRadius: "5px",
35
textAlign: "center" as const,
36
};
37
38
const text = {
39
margin: "0 0 10px 0",
40
textAlign: "left" as const,
41
};
42
43
const button = {
44
fontSize: "14px",
45
font: "bold",
46
backgroundColor: "#28a745",
47
color: "#fff",
48
lineHeight: 1.5,
49
borderRadius: "0.2em",
50
textAlign: "center" as const,
51
};
52
53
function BasicEmail({ name, text }: { name: string; text: string }) {
54
return (
55
<Html>
56
<Head />
57
<Preview>Welcome to Acme Inc!</Preview>
58
<Container style={container}>
59
<Section style={section}>
60
<Text>Hey {name}!</Text>
61
<Text>{text}</Text>
62
<Button style={button} pY={4} pX={4} href="https://acmecompany.inc/">
63
Get started
64
</Button>
65
</Section>
66
</Container>
67
</Html>
68
);
69
}
70
71
// This job sends a basic email built using React and Typescript
72
client.defineJob({
73
id: "resend-send-react-email",
74
name: "Resend: send react email",
75
version: "1.0.0",
76
trigger: eventTrigger({
77
name: "send.email",
78
schema: z.object({
79
to: z.string(),
80
subject: z.string(),
81
text: z.string(),
82
name: z.string(),
83
// The 'from' email address must be a verified domain in your Resend account.
84
from: z.string(),
85
}),
86
}),
87
integrations: {
88
resend,
89
},
90
run: async (payload, io, ctx) => {
91
await io.resend.sendEmail("send-email", {
92
to: payload.to,
93
subject: payload.subject,
94
text: payload.text,
95
from: payload.from,
96
// BasicEmail is the custom React component that will be used to style the email
97
react: <BasicEmail name={payload.name} text={payload.text} />,
98
});
99
},
100
});