Skip to content

Newsletter

ShipSaaS supports Resend and Beehiiv to manage email subscriptions.

ShipSaaS supports Resend and Beehiiv as built-in providers.

Create a Resend account at resend.com, and add and verify your website’s domain.

Navigate to Resend Dashboard > API Keys, create a new API key, and ensure that it has permission to send emails.

Add the following to your .env file:

.env

Terminal window
RESEND_API_KEY=re_xxxxxxxxxxxx

Note: When using Resend, the RESEND_API_KEY is shared between the email module and the email subscription module.

Update your website configuration to use Resend for email subscription management:

src/config/website.ts

export const websiteConfig = {
// ...other configurations
newsletter: {
enable: true,
provider: 'resend',
autoSubscribeAfterSignUp: true, // Whether to automatically subscribe users after registration
},
// ...other configurations
}

Create a Beehiiv account at beehiiv.com.

  • Navigate to Settings > API to generate an API key.
  • Obtain your Publication ID from the URL or the settings page.

Add the following to your .env file:

.env

Terminal window
BEEHIIV_API_KEY=your-beehiiv-api-key
BEEHIIV_PUBLICATION_ID=your-beehiiv-publication-id

Update your website configuration to use Beehiiv for email subscription management:

src/config/website.ts

export const websiteConfig = {
// ...other configurations
newsletter: {
enable: true,
provider: 'beehiiv',
autoSubscribeAfterSignUp: true, // Whether to automatically subscribe users after registration
},
// ...other configurations
}

If you are setting up your environment, you can now return to the Environment Configuration document and continue. The remainder of this document can be read later.

Environment configuration set environment variables


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

  1. Create a new file in the src/newsletter/provider directory.
  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 email subscription provider
}
public getProviderName(): string {
return 'custom';
}
async subscribe({ email }: SubscribeNewsletterParams): Promise<boolean> {
// Implementation to subscribe a user
return true;
}
async unsubscribe({ email }: UnsubscribeNewsletterParams): Promise<boolean> {
// Implementation to unsubscribe a user
return true;
}
async checkSubscribeStatus({ email }: CheckSubscribeStatusParams): Promise<boolean> {
// Implementation to check subscription status
return true;
}
}
  1. Register the new email subscription provider in the providerRegistry in src/newsletter/index.ts:

src/newsletter/index.ts

import { CustomNewsletterProvider } from './provider/custom-provider';
const providerRegistry: Record<NewsletterProviderName, ProviderFactory> = {
resend: () => new ResendNewsletterProvider(),
beehiiv: () => new BeehiivNewsletterProvider(),
custom: () => new CustomNewsletterProvider(),
};

Now that you know how to use email subscriptions in ShipSaaS, explore these related topics: