๐Ÿ“ง

Transactional Emails

๐Ÿ‘จโ€๐Ÿณ Chefโฑ๏ธ 25 minutes

๐Ÿ“‹ Suggested prerequisites

  • โ€ขNode.js
  • โ€ขREST API

What you'll build

An automatic email sending system that notifies your users when they register, make a purchase, or any important event in your application. You'll use Resend (or SendGrid) to send personalized HTML emails with your brand, including templates created with React Email that you can preview before sending. When finished, you'll have reusable functions to send different types of transactional emails from anywhere in your backend.


Recommended services

ServiceFreeIdeal for
Resend3000/monthDevelopers
SendGrid100/dayEnterprise
Postmark100/monthTransactional

Resend Setup

pnpm add resend

Code

import { Resend } from 'resend'

const resend = new Resend(process.env.RESEND_API_KEY)

export async function sendWelcomeEmail(to: string, name: string) {
  await resend.emails.send({
    from: 'Your App <noreply@yourdomain.com>',
    to,
    subject: 'Welcome!',
    html: `
      <h1>Hello ${name}!</h1>
      <p>Thanks for signing up.</p>
    `
  })
}

With React Email

import { render } from '@react-email/render'
import WelcomeEmail from './emails/Welcome'

const html = render(<WelcomeEmail name={name} />)
await resend.emails.send({ ..., html })

Next step

โ†’ Deploy with Docker