Setting Up Resend
Follow these steps to configure Resend as your email provider for sending transactional emails and allowing magic login links.
Setup
- Go to the Resend website and create an account.
- Once logged in, navigate to the API Keys section.
- Create a new API key and copy it. You’ll need this key in the next step.
- In your project’s
.env.local
file, add the following environment variable and paste the value:RESEND_API_KEY= your-resend-api-key
Sending Transactional Emails
To send emails, you’ll use the helper function sendEmail
from the lib/email.ts
file.
Helper Function: lib/email.ts
import { Resend } from 'resend';
import { FROM_EMAIL } from './consts';
const resend = new Resend(process.env.RESEND_API_KEY);
export const sendEmail = async (
to: string | string[],
subject: string,
html: string,
from?: string
) => {
await resend.emails.send({
from: from || FROM_EMAIL,
to,
subject,
html,
});
};