Resend

Nuxtbe uses Resend for sending transactional emails in two key areas:

  1. Server Routes: For payment-related transactional emails in:
    • LemonSqueezy webhook (/api/webhook/lemonsqueezy)
    • Stripe webhook (/api/webhook/stripe)
  2. Supabase Edge Functions: For authentication-related emails:
    • Welcome emails
    • Password reset
    • Email verification
    • Magic link authentication

This guide will help you set up and configure Resend for both use cases.

Setup

Create Resend Account

  1. Sign up for a Resend account.
  2. Complete your account verification.

Generate API Key

  1. Navigate to the API Keys section in your Resend Dashboard.
  2. Click "Create API Key".
  3. Give your key a descriptive name (e.g., "Nuxtbe Production").
  4. Copy the generated API key.
  5. Store it in your .env file:
.env
RESEND_API_KEY="re_..."

Add Sending Domain

  1. Go to the Domains section in your Resend Dashboard.
  2. Click "Add Domain".
  3. Follow the DNS verification steps.
  4. Wait for domain verification (usually takes a few minutes).

Configure Contact Email

Update your app.config.ts with your contact email:

app.config.ts
export default defineAppConfig({
  general: {
    contactEmail: '[email protected]', // Change this to your verified domain email
  },
  // ... other config
});

Configure API Keys

  1. Navigate to the API Keys section in your Resend Dashboard.
  2. Create two API keys:
    • One for your Nuxt application
    • One for Supabase Edge Functions
  3. Store the Nuxt API key in your .env:
.env
RESEND_API_KEY="re_..."
  1. Add the Supabase Edge Functions API key to your Edge Function Secrets:
RESEND_API_KEY="re_..."

Usage

Send Email

Nuxtbe ships emailServerClient utility to configure the email client in your server routes and send emails from there.

const { sendEmail } = emailServerClient(event);

await sendEmail({
  from: 'Your App <[email protected]>',
  to: '[email protected]',
  subject: 'Welcome!',
  html: '<p>Welcome to our application!</p>',
});

Add Contact to Audience

const { addContact } = emailServerClient(event);

await addContact('[email protected]', 'John Doe');

Email Templates

Nuxtbe includes pre-built email templates powered by React Email for:

  • Welcome emails
  • Password reset
  • Email verification
  • One-time login link

These templates are used within Supabase Edge Functions to send transactional emails. They are located in the supabase/functions/send-email-mail-hook/_templates directory and can be customized using React Email components to match your branding. React Mail has been chosen because of smaller bundle size and better performance. In future, it can be replaced by Vue Mail.

Testing Emails

  1. Use the Resend Dashboard to monitor sent emails.
  2. Check the delivery status and open rates.
  3. View rendered email content and debug issues.

Best Practices

  1. Always verify your sending domain
  2. Implement proper error handling:
mailSender.ts
try {
  await sendEmail({
    from: 'Your App <[email protected]>',
    to: userEmail,
    subject: 'Welcome!',
    html: welcomeTemplate(user),
  });
} catch (error) {
  console.error('Failed to send email:', error);
  // Handle error appropriately
}
  1. Monitor email deliverability in the Resend dashboard
  2. Keep email templates mobile-responsive
  3. Follow anti-spam guidelines

Additional Resources