LogoMkSaaS Docs
LogoMkSaaS Docs
HomepageIntroductionCodebaseVideo TutorialsGetting StartedEnvironment Setup
Configuration

Integrations

DatabaseAuthenticationEmailNewsletterStoragePaymentCreditsCron JobsAIAnalyticsNotificationCaptchaChatboxAffiliates

Customization

MetadataFontsThemesImagesi18nBlogDocsComponentsCustom PagesLanding PageUser Management

Codebase

IDE SetupProject StructureFormatting & LintingUpdating the Codebase
X (Twitter)

Newsletter

Learn how to set up and use Resend or Beehiiv for newsletter management

MkSaaS supports multiple newsletter service providers for managing email subscriptions. Currently, it supports Resend and Beehiiv, providing flexible options to manage newsletter subscriptions for your users.

Provider Options

ProviderBest ForKey Features
ResendDevelopers who need simple email + newsletterSimple API, Email sending + Contacts management
BeehiivContent creators and professional newslettersRich analytics, Monetization, Growth tools

Setup with Resend

  1. Create a Resend account at resend.com
  2. Click API Keys > Create API Key in the dashboard, set the permissions to Send emails or Full access
  3. Get the API key from the dashboard, and add it to .env file:
.env
RESEND_API_KEY=YOUR-RESEND-API-KEY
  1. Update the website config to use Resend for newsletter management:
src/config/website.tsx
export const websiteConfig = {
  // ...other config
  newsletter: {
    provider: 'resend', // Newsletter service provider to use
    autoSubscribeAfterSignUp: false, // Whether to automatically subscribe users after sign up
  },
  // ...other config
}

Setup with Beehiiv

  1. Create a Beehiiv account at beehiiv.com
  2. Go to Settings > API to generate an API key
  3. Get your Publication ID from the URL or settings page
  4. Add the credentials to .env file:
.env
BEEHIIV_API_KEY=YOUR-BEEHIIV-API-KEY
BEEHIIV_PUBLICATION_ID=YOUR-BEEHIIV-PUBLICATION-ID
  1. Update the website config to use Beehiiv for newsletter management:
src/config/website.tsx
export const websiteConfig = {
  // ...other config
  newsletter: {
    provider: 'beehiiv', // Newsletter service provider to use
    autoSubscribeAfterSignUp: false, // Whether to automatically subscribe users after sign up
  },
  // ...other config
}

If you are setting up the environment, now you can go back to the Environment Setup guide and continue. The rest of this guide can be read later.

Environment Setup

Set up environment variables


Newsletter System Structure

The newsletter system in MkSaaS is designed with the following components:

resend.ts
beehiiv.ts
index.ts
types.ts
README.md

This modular structure makes it easy to extend the newsletter system with new providers if needed.

Core Features

  • Newsletter subscription and unsubscription management
  • Multiple provider support (Resend and Beehiiv)
  • User subscription status checking
  • Optional automatic subscription for new users
  • Modular architecture for easy newsletter service provider switching
  • Provider-agnostic interface for consistent API across different services

Usage

Basic Usage

MkSaaS provides simple utility functions for newsletter management.

import { subscribe, unsubscribe, isSubscribed } from '@/newsletter';

// Subscribe a user to the newsletter
const success = await subscribe('user@example.com');

// Unsubscribe a user from the newsletter
const success = await unsubscribe('user@example.com');

// Check if a user is subscribed
const subscribed = await isSubscribed('user@example.com');

Using with Email Templates

You can combine the newsletter functionality with the email system to send confirmation emails:

import { subscribe } from '@/newsletter';
import { sendEmail } from '@/mail';

export async function subscribeWithConfirmation(email: string) {
  // Subscribe the user to the newsletter
  const success = await subscribe(email);

  if (success) {
    // Send a confirmation email to the user
    await sendEmail({
      to: email,
      template: 'subscribeNewsletter',
      context: {
        name: email.split('@')[0], // Simple name extraction
        unsubscribeUrl: `https://example.com/unsubscribe?email=${encodeURIComponent(email)}`,
      },
    });
  }

  return success;
}

Customization

Creating a Custom Provider

If you need to use a different newsletter service, you can create a custom provider:

  1. Create a new file in the src/newsletter/provider directory as a custom newsletter service provider
  2. Implement the NewsletterProvider interface
src/newsletter/provider/custom-provider.ts
import type {
  CheckSubscribeStatusParams,
  NewsletterProvider,
  SubscribeNewsletterParams,
  UnsubscribeNewsletterParams,
} from '@/newsletter/types';

export class CustomNewsletterProvider implements NewsletterProvider {
  constructor() {
    // Initialize your provider
  }

  public getProviderName(): string {
    return 'CustomProvider';
  }

  async subscribe({ email }: SubscribeNewsletterParams): Promise<boolean> {
    // Implementation for subscribing a user
    return true;
  }

  async unsubscribe({ email }: UnsubscribeNewsletterParams): Promise<boolean> {
    // Implementation for unsubscribing a user
    return true;
  }

  async checkSubscribeStatus({ email }: CheckSubscribeStatusParams): Promise<boolean> {
    // Implementation for checking subscription status
    return true;
  }
}
  1. Update the provider selection logic in index.ts:
src/newsletter/index.ts
import { CustomNewsletterProvider } from './provider/custom-provider';

export const initializeNewsletterProvider = (): NewsletterProvider => {
  if (!newsletterProvider) {
    switch (websiteConfig.newsletter.provider) {
      case 'resend':
        newsletterProvider = new ResendNewsletterProvider();
        break;
      case 'beehiiv':
        newsletterProvider = new BeehiivNewsletterProvider();
        break;
      case 'custom':
        newsletterProvider = new CustomNewsletterProvider();
        break;
      default:
        throw new Error(
          `Unsupported newsletter provider: ${websiteConfig.newsletter.provider}`
        );
    }
  }

  return newsletterProvider;
};

FAQ

Which provider should I choose?

  • Choose Resend if you already use Resend for transactional emails and want a simple, unified solution for both email sending and newsletter management.
  • Choose Beehiiv if you need advanced newsletter features like analytics, monetization, referral programs, and growth tools for professional content creators.

RESEND_AUDIENCE_ID Environment Variable

As of November 15, 2025, the RESEND_AUDIENCE_ID environment variable has been removed from the template, and the newsletter module no longer needs this environment variable.

Please refer to the documentation for more details: Migrating from Audiences to Segments

Best Practices

  1. Validate Email Addresses: Always validate email addresses before subscribing users
  2. Confirmation Emails: Send confirmation emails when users subscribe to the newsletter
  3. Unsubscribe Link: Always include an unsubscribe link in your newsletter emails
  4. Privacy Policy: Make sure your website has a privacy policy explaining how you use user subscribed data

Video Tutorial

Next Steps

Now that you understand how to work with newsletters in MkSaaS, explore these related integrations:

Email

Configure email services

Authentication

Configure user authentication

Analytics

Configure analytics

Storage

Configure storage

Table of Contents

Provider Options
Setup with Resend
Setup with Beehiiv
Newsletter System Structure
Core Features
Usage
Basic Usage
Using with Email Templates
Customization
Creating a Custom Provider
FAQ
Which provider should I choose?
RESEND_AUDIENCE_ID Environment Variable
Best Practices
Video Tutorial
Next Steps