Back to APIs

Send, delete and filter emails and more.

Using our official SendGrid integration

Create any tasks possible with the SendGrid API.

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

SendGrid integration docs

Example code using SendGrid

Below are some working code examples of how you can use SendGrid 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 { SendGrid } from "@trigger.dev/sendgrid";
3
import { z } from "zod";
4
5
export
6
const sendgrid = new SendGrid({
7
id: "sendgrid",
8
apiKey: process.env.SENDGRID_API_KEY!,
9
});
10
11
// This job sends a basic email to a 'to' email address, a 'subject', a 'text' field and a 'from' email address.
12
client.defineJob({
13
id: "sendgrid-send-basic-email",
14
name: "SendGrid: send basic email",
15
version: "1.0.0",
16
trigger: eventTrigger({
17
name: "send.email",
18
schema: z.object({
19
to: z.string(),
20
subject: z.string(),
21
text: z.string(),
22
// The 'from' email address must be a verified domain in your SendGrid account.
23
from: z.string(),
24
}),
25
}),
26
integrations: {
27
sendgrid,
28
},
29
run: async (payload, io, ctx) => {
30
await io.sendgrid.sendEmail("send-email", {
31
to: payload.to,
32
from: payload.from,
33
subject: payload.subject,
34
text: payload.text,
35
});
36
},
37
});