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 ๐
- A Resend account (sign up at resend.com)
- Access to your domain's DNS settings
- Domain verified in Resend
Domain Verification ๐
- Go to Resend Dashboard
- Navigate to Domains > Add Domain
- Follow the DNS verification steps
- 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 ๐งช
- Send a test email using Resend dashboard
- Monitor delivery in Resend logs
- Check email headers for proper authentication
Important Notes โ ๏ธ
- DNS propagation takes time (24-48 hours)
- Monitor email reputation in Resend dashboard
- Keep bounce rate low
- 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! ๐