Back to jobs

Sends an email using SendGrid

Trigger: eventTrigger

Sends a basic email using SendGrid.

Integrations:

/src/sendGridSendBasicEmail

Marketing

1
import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";
2
import { SendGrid } from "@trigger.dev/sendgrid";
3
import { z } from "zod";
4
5
export const client = new TriggerClient({ id: "jobs-showcase" });
6
7
const sendgrid = new SendGrid({
8
id: "sendgrid",
9
apiKey: process.env.SENDGRID_API_KEY!,
10
});
11
12
// This job sends a basic email to a 'to' email address, a 'subject', a 'text' field and a 'from' email address.
13
client.defineJob({
14
id: "sendgrid-send-basic-email",
15
name: "SendGrid: send basic email",
16
version: "1.0.0",
17
trigger: eventTrigger({
18
name: "send.email",
19
schema: z.object({
20
to: z.string(),
21
subject: z.string(),
22
text: z.string(),
23
// The 'from' email address must be a verified domain in your SendGrid account.
24
from: z.string(),
25
}),
26
}),
27
integrations: {
28
sendgrid,
29
},
30
run: async (payload, io, ctx) => {
31
await io.sendgrid.sendEmail("send-email", {
32
to: payload.to,
33
from: payload.from,
34
subject: payload.subject,
35
text: payload.text,
36
});
37
},
38
});
39
40
// These lines can be removed if you don't want to use express
41
import { createExpressServer } from "@trigger.dev/express";
42
createExpressServer(client);