The newsletter system has been completely rebuilt to actually send real emails to your subscribers. Here's how to get it working:
Create a .env file in your project root with the following content:
# SMTP Configuration for Newsletter System
VITE_SMTP_HOST=smtp.gmail.com
VITE_SMTP_PORT=587
VITE_SMTP_SECURE=false
VITE_SMTP_USER=phcoder.blog@gmail.com
VITE_SMTP_PASS=your_app_password_here-
Enable 2-Factor Authentication
- Go to https://myaccount.google.com/security
- Enable 2-Step Verification if not already enabled
-
Generate App Password
- Go to https://myaccount.google.com/apppasswords
- Select "Mail" as the app
- Select "Other" as the device (name it "Blog Newsletter")
- Click "Generate"
- Copy the 16-character app password
- Replace
your_app_password_herein the .env file
- Go to your admin dashboard
- Click the "Test Newsletter" button (green button with envelope icon)
- Use the test panel to verify each component
- Test SMTP Connection - Verifies your email credentials
- Test Newsletter System - Checks database connectivity
- Test Email Sending - Sends a test email to verify delivery
- Test Subscription - Tests the full subscription flow
- Test Unsubscription - Tests the unsubscription flow
- ❌ Mock email service (no real emails sent)
- ❌ SimpleSmtpService was just simulation
- ❌ No real SMTP connection
- ❌ Frontend showed success but no actual emails
- ✅ Real email delivery via Nodemailer
- ✅ Proper SMTP connection to Gmail
- ✅ Welcome emails sent on subscription
- ✅ Blog notification emails sent to all subscribers
- ✅ Unsubscribe confirmation emails
- ✅ Comprehensive error handling and logging
- ✅ Test panel for debugging
-
User Subscribes
- Email stored in Firebase
- Welcome email sent immediately
- User added to subscriber list
-
Admin Creates Blog
- Blog saved to database
- Newsletter notification triggered
- All subscribers receive email with blog details
- Unsubscribe link included in each email
-
User Unsubscribes
- User removed from Firebase
- Confirmation email sent
- No more emails received
-
"SMTP authentication failed"
- Check your app password is correct
- Ensure 2FA is enabled on Gmail
- Verify email address in .env file
-
"Failed to connect to SMTP server"
- Check internet connection
- Verify SMTP host and port
- Ensure firewall isn't blocking port 587
-
"Email sent but not received"
- Check spam/junk folder
- Wait 5-10 minutes for delivery
- Verify recipient email is correct
-
Check Console Logs
- Open browser developer tools
- Look for detailed email logs
- Check for error messages
-
Test Individual Components
- Use the test panel systematically
- Test SMTP connection first
- Then test email sending
- Finally test full subscription flow
-
Verify Environment Variables
- Ensure .env file is in project root
- Check variable names match exactly
- Restart development server after changes
- Gmail Limits: 500 emails per day
- Rate Limiting: 100ms delay between emails to avoid overwhelming SMTP
- Batch Processing: Emails sent sequentially for reliability
- Error Handling: Failed emails logged but don't stop the process
- Set up your .env file with real Gmail credentials
- Test the SMTP connection using the test panel
- Subscribe a test email to verify the full flow
- Create a test blog post to test notifications
- Monitor the console for detailed logs
If you're still having issues:
- Check the browser console for error messages
- Verify your Gmail app password is correct
- Ensure your .env file is properly formatted
- Test with a different email address
- Check if your Gmail account has any restrictions
The system now provides detailed logging, so you should see exactly what's happening at each step!