Skip to content

Resend Email Provider

To use Resend as your email provider, you need to create an account and obtain your API Key

Then copy your API key and add it to the .env file

RESEND_API_KEY='your-resend-api-key'

The code for Resend is found in server/_/mail/poviders/resend.ts

ts
import { Resend } from 'resend'
import type {
  SendEmailHandler,
  SendEmailParams,
  SendEmailWithHtml,
  SendEmailWithText,
} from '~/server/_/mail/types'

const config = useRuntimeConfig()
const resend = new Resend(config.resendApiKey)

export const send: SendEmailHandler = async (params: SendEmailParams) => {
  const { subject, recipient: to } = params

  // Type assertion to safely access html and text properties
  const html = (params as SendEmailWithHtml).html
  const text = (params as SendEmailWithText).text

  await resend.emails.send({
    from: config.emailSenderAddress,
    to,
    subject,
    html,
    text,
  })
}

For more information, pleasw refer to the Resend docs