This guide will help you set up your preferred email service provider for the newsletter signup functionality.
Setup Steps:
- Go to Mailchimp and create an account
- Create an audience (mailing list)
- Get your API key: Account → Extras → API keys
- Get your Audience ID: Audience → Settings → Audience name and defaults
Environment Variables: ```env MAILCHIMP_API_KEY=your_api_key-us1 MAILCHIMP_AUDIENCE_ID=your_audience_id ```
Features:
- Free up to 2,000 contacts
- Great templates and automation
- Detailed analytics
- Easy to use interface
Setup Steps:
- Sign up at ConvertKit
- Create a form for your newsletter
- Get your API key: Account Settings → API
- Get your Form ID from the form settings
Environment Variables: ```env CONVERTKIT_API_KEY=your_api_key CONVERTKIT_FORM_ID=your_form_id ```
Features:
- Creator-focused features
- Advanced automation
- Landing pages included
- Great for course creators
Setup Steps:
- Create account at EmailOctopus
- Create a list
- Get API key from Settings → API
- Get List ID from your list settings
Environment Variables: ```env EMAILOCTOPUS_API_KEY=your_api_key EMAILOCTOPUS_LIST_ID=your_list_id ```
Features:
- Very affordable pricing
- Built on Amazon SES
- Simple and clean interface
- Good deliverability
Setup Steps:
- Sign up at Buttondown
- Get your API key from Settings → Programming
Environment Variables: ```env BUTTONDOWN_API_KEY=your_api_key ```
Features:
- Markdown-based newsletters
- Great for technical content
- Simple pricing
- RSS integration
-
Choose your provider in
lib/email-services.ts: ```typescript export const emailServiceConfig: EmailServiceConfig = { provider: 'mailchimp', // Change this to your chosen provider // ... other config } ``` -
Add environment variables to
.env.local -
Test the integration by submitting the newsletter form
If you're using a different service or have a custom endpoint:
```typescript export const emailServiceConfig: EmailServiceConfig = { provider: 'custom', customEndpoint: 'https://your-api.com/subscribe' } ```
Your endpoint should accept POST requests with: ```json { "email": "user@example.com", "firstName": "John", "lastName": "Doe", "source": "website-blog" } ```
The integration includes Google Analytics event tracking for successful subscriptions:
```javascript gtag('event', 'newsletter_signup', { event_category: 'engagement', event_label: 'blog_newsletter', value: 1 }) ```
The system handles common scenarios:
- Invalid email addresses
- Duplicate subscriptions
- Network errors
- API rate limits
- Service downtime
Test your integration by:
- Subscribing with a test email
- Checking your email service dashboard
- Verifying confirmation emails are sent
- Testing error scenarios (invalid emails, etc.)
- API keys are stored as environment variables
- Never commit API keys to version control
- Use different API keys for development and production
- Regularly rotate your API keys
- Monitor API usage and set up alerts
Each email service provider has detailed documentation: