Resend Setup

Learn how to set up Resend for reliable email delivery

Setting Up Resend ๐Ÿ“ง

This guide will help you set up Resend for reliable email delivery in your application.

Prerequisites ๐Ÿ“‹

  1. A Resend account (sign up at resend.com)
  2. Access to your domain's DNS settings
  3. Domain verified in Resend

Domain Verification ๐Ÿ”

  1. Go to Resend Dashboard
  2. Navigate to Domains > Add Domain
  3. Follow the DNS verification steps
  4. Add the provided DNS records to your domain

Implementation ๐Ÿ’ป

Install required dependencies:

pnpm add resend

Create src/lib/email/sendMail.ts:

import { Resend } from "resend";
import { appConfig } from "../config";

const sendMail = async (to: string, subject: string, html: string) => {
  if (process.env.NODE_ENV !== "production") {
    console.log(
      "Sending email to",
      to,
      "with subject",
      subject,
      "and html",
      html
    );
    return;
  }

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

  const response = await resend.emails.send({
    from: `${appConfig.email.senderName} <${appConfig.email.senderEmail}>`,
    to: [to],
    subject: subject,
    html: html,
    replyTo: appConfig.email.senderEmail,
  });

  if(response.error) {
    console.error("Email sent failed", response.error);
  } else {
    if(process.env.NODE_ENV === "development") {
      console.info("Email sent successfully", response);
    }
  }
};

export default sendMail;

Environment Variables ๐Ÿ”

Add these to your .env.local:

RESEND_API_KEY=your_api_key

Testing Email Setup ๐Ÿงช

  1. Send a test email using Resend dashboard
  2. Monitor delivery in Resend logs
  3. Check email headers for proper authentication

Important Notes โš ๏ธ

  1. DNS propagation takes time (24-48 hours)
  2. Monitor email reputation in Resend dashboard
  3. Keep bounce rate low
  4. Use production API key in production

Remember to wait for DNS propagation before testing your email setup. Rushing this process can lead to delivery issues! ๐Ÿš€