GuidesEmail

Configuration

This guide will help you configure transactional and marketing emails in the Next.js Supabase SaaS template using the Resend email provider, including setting up custom email functions.

Overview

Emails play a crucial role in business communication, whether it's providing users with necessary information or engaging them with promotional content. In the Next.js Supabase SaaS template, email notifications are categorized into two primary types:

  1. Transactional Emails: Automated emails sent to individual recipients based on a specific action or event. These emails use pre-built and customized templates, including Supabase Auth templates.

  2. Marketing Emails: Emails sent to a group of recipients as part of a broader strategy to promote products or features. Examples include newsletters, product updates, and new feature announcements.

This documentation explains how email notifications, both transactional and marketing, are handled in the Next.js Supabase SaaS template using the Resend mail provider using API.

Marketing Emails

Marketing emails are sent to users who have opted in to receive promotional content, such as product updates and new feature announcements. In the template, the Resend mail provider is used to manage marketing email campaigns. Marketing emails are only sent to users who have given consent to receive these communications.

Email Service Provider: Resend

The Next.js Supabase SaaS template integrates with Resend, an email provider, to send both transactional and marketing emails. Below is an outline of the configuration required to set up Resend.

Resend API Configuration

To send both transactional and marketing emails, you need a valid Resend account and the following environment variables configured:

# Environment Variables for Resend Email Services
RESEND_FROM_EMAIL=
RESEND_API_KEY=
RESEND_AUDIENCE_ID=
RESEND_WEBHOOK_SECRET=

For more details on setting up a Resend account, please refer to the Resend Setup Documentation.

Server Configuration

In the server.config.ts file, the following email settings need to be configured to handle specific types of emails:

emails: {
  onboarding: {
    active: true,
    from: 'support', // Replace with a domain-specific email address
  },
  upgrade: {
    active: true,
    from: 'billing',
  },
  downgrade: {
    active: true,
    from: 'billing',
  },
  deletion: {
    active: true,
    from: 'support',
  },
},

This configuration ensures that the appropriate email addresses are used for different email types, enhancing brand recognition and trustworthiness.

Custom Email Functions

The template comes with pre-built email functions located in /utils/email.ts. These functions handle various features such as:

  • Sending onboarding invites to new members
  • Notifying users about account upgrades or downgrades
  • Confirming account deletions

You are encouraged to customize these functions to meet your specific business needs. For example, adding a custom email notification for product launches or promotional events can be done by modifying the existing functions.

Customizing Email Providers

Although Resend is the recommended email provider, you may opt to integrate with other email services by adding custom email functions. If you choose to do so, update both the server.config.ts file and the environment variables accordingly.

On this page