Back to jobs
Trigger: eventTrigger
This job sends a basic email built using React & Typescript to a 'to' email address, a 'subject', a 'text' field and a 'from' email address.
Integrations:
/src/resendSendReactEmail
Marketing
1// src/resendSendReactEmail.tsx23import { TriggerClient, eventTrigger } from "@trigger.dev/sdk";4import { Resend } from "@trigger.dev/resend";5import { z } from "zod";67// react-email imports8import { Html } from "@react-email/html";9import { Head } from "@react-email/head";10import { Text } from "@react-email/text";11import { Button } from "@react-email/button";12import { Section } from "@react-email/section";13import { Preview } from "@react-email/preview";14import { Container } from "@react-email/container";1516const client = new TriggerClient({ id: "jobs-showcase" });1718const resend = new Resend({19id: "resend",20apiKey: process.env.RESEND_API_KEY!,21});2223// Email styling24const container = {25width: "480px",26margin: "0 auto",27padding: "20px 0 48px",28};2930const title = {31fontSize: "24px",32lineHeight: 1.25,33};3435const section = {36padding: "24px",37border: "solid 1px #dedede",38borderRadius: "5px",39textAlign: "center" as const,40};4142const text = {43margin: "0 0 10px 0",44textAlign: "left" as const,45};4647const button = {48fontSize: "14px",49font: "bold",50backgroundColor: "#28a745",51color: "#fff",52lineHeight: 1.5,53borderRadius: "0.2em",54textAlign: "center" as const,55};5657function BasicEmail({ name, text }: { name: string; text: string }) {58return (59<Html>60<Head />61<Preview>Welcome to Acme Inc!</Preview>62<Container style={container}>63<Section style={section}>64<Text>Hey {name}!</Text>65<Text>{text}</Text>66<Button style={button} pY={4} pX={4} href="https://acmecompany.inc/">67Get started68</Button>69</Section>70</Container>71</Html>72);73}7475// This job sends a basic email built using React and Typescript76client.defineJob({77id: "resend-send-react-email",78name: "Resend: send react email",79version: "1.0.0",80trigger: eventTrigger({81name: "send.email",82schema: z.object({83to: z.string(),84subject: z.string(),85text: z.string(),86name: z.string(),87// The 'from' email address must be a verified domain in your Resend account.88from: z.string(),89}),90}),91integrations: {92resend,93},94run: async (payload, io, ctx) => {95await io.resend.sendEmail("send-email", {96to: payload.to,97subject: payload.subject,98text: payload.text,99from: payload.from,100// BasicEmail is the custom React component that will be used to style the email101react: <BasicEmail name={payload.name} text={payload.text} />,102});103},104});105106// These lines can be removed if you don't want to use express107import { createExpressServer } from "@trigger.dev/express";108createExpressServer(client);