Getting started

If you have not yet set up Trigger.dev in your project, go to the quick start guide.

Installation

npm install @trigger.dev/sendgrid@latest

Authentication

SendGrid integration supports API Keys. To authenticate, you’ll need to create an instance of the SendGrid class and provide your API key.

import { SendGrid } from "@trigger.dev/sendgrid";

const sendgrid = new SendGrid({
  id: "sendgrid",
  apiKey: process.env.SENDGRID_API_KEY!,
});

Example

In this example we use Zod, a TypeScript-first schema declaration and validation library.

import { SendGrid } from "@trigger.dev/sendgrid";
import { Job, eventTrigger } from "@trigger.dev/sdk";
import { z } from "zod";

// Create an instance of SendGrid
const sendgrid = new SendGrid({
  id: "sendgrid",
  apiKey: process.env.SENDGRID_API_KEY!,
});

// Define a Trigger.dev job
client.defineJob({
  id: "send-sendgrid-email",
  name: "Send SendGrid Email",
  version: "0.1.0",
  trigger: eventTrigger({
    name: "send.email",
    schema: z.object({
      to: z.string(),
      subject: z.string(),
      text: z.string(),
    }),
  }),
  integrations: {
    sendgrid,
  },
  run: async (payload, io, ctx) => {
    await io.sendgrid.sendEmail({
      to: payload.to,
      from: "Trigger.dev <[email protected]>",
      subject: payload.subject,
      text: payload.text,
    });
  },
});

Tasks

Function NameDescription
sendEmailSend an email