Newsletter
Learn how to set up and use Resend for newsletter subscription management
TanStarter uses Resend to manage newsletter subscriptions.
Setup
Create Resend Account
Create a Resend account at resend.com.
Get API Key
Click API Keys > Create API Key, set permissions to Send emails or Full access. Copy the API Key and add it to your environment file:
RESEND_API_KEY=your-resend-api-keyUpdate Website Configuration
Update the website configuration to use Resend for newsletter management:
export const websiteConfig = {
// ...other config
newsletter: {
enable: true,
provider: 'resend',
autoSubscribeAfterSignUp: true, // Auto-subscribe users after registration
},
// ...other config
}If you are setting up your environment, you can now go back to the Environment Configuration and continue. The rest of this document can be read later.
Environment Configuration
Set up environment variables
Customization
Creating a Custom Provider
If you need to use a different newsletter service, you can create a custom provider:
- Create a new file in the
src/newsletter/providerdirectory - Implement the
NewsletterProviderinterface
import type {
CheckSubscribeStatusParams,
NewsletterProvider,
SubscribeNewsletterParams,
UnsubscribeNewsletterParams,
} from '@/newsletter/types';
export class CustomNewsletterProvider implements NewsletterProvider {
constructor() {
// Initialize your newsletter service provider
}
public getProviderName(): string {
return 'custom';
}
async subscribe({ email }: SubscribeNewsletterParams): Promise<boolean> {
// Subscribe user implementation
return true;
}
async unsubscribe({ email }: UnsubscribeNewsletterParams): Promise<boolean> {
// Unsubscribe user implementation
return true;
}
async checkSubscribeStatus({ email }: CheckSubscribeStatusParams): Promise<boolean> {
// Check subscription status implementation
return true;
}
}- Register the new provider in the
providerRegistryinsrc/newsletter/index.ts:
import { CustomNewsletterProvider } from './provider/custom-provider';
const providerRegistry: Record<NewsletterProviderName, ProviderFactory> = {
resend: () => new ResendNewsletterProvider(),
custom: () => new CustomNewsletterProvider(),
};Next Steps
Now that you understand how to use newsletter subscriptions in TanStarter, you might want to explore these related features:
TanStarter Docs