A professional, secure email-sending service built with Next.js, TypeScript, and Nodemailer. Features encrypted SMTP connections, multiple provider support, and beautiful HTML email templates.
- Secure SMTP Configuration: TLS/SSL encryption enforced
- Multiple SMTP Providers: Gmail, SendGrid, Mailgun, AWS SES, Outlook
- Professional Email Templates: HTML templates with inline CSS
- Environment Variable Security: No hardcoded credentials
- Input Validation & Sanitization: Prevents injection attacks
- Error Handling: Comprehensive error handling and logging
- Real-time Testing: Send test emails to real addresses
- Health Check Endpoint: Monitor SMTP service status
- Node.js 18+ and npm/yarn
- SMTP provider account (Gmail, SendGrid, etc.)
- Environment variables configured
-
Clone and install dependencies: ```bash npm install ```
-
Configure environment variables: ```bash cp .env.example .env.local ```
-
Edit
.env.localwith your SMTP credentials: ```env SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_USER=your-email@gmail.com SMTP_PASS=your-app-password FROM_EMAIL=your-email@gmail.com FROM_NAME=Your App Name ``` -
Start the development server: ```bash npm run dev ```
- Enable 2-Factor Authentication
- Generate App Password: Google Account → Security → App passwords
- Use the 16-character app password in
SMTP_PASS
- Create SendGrid account
- Generate API key
- Use
apikeyasSMTP_USERand API key asSMTP_PASS
- Create Mailgun account
- Add and verify your domain
- Use SMTP credentials from Mailgun dashboard
- Set up AWS SES and verify domain/email
- Create SMTP credentials in SES console
- Use provided SMTP username and password
The service includes three professional email templates:
- Welcome Email: User onboarding with call-to-action
- Notification Email: System alerts and updates
- Custom Email: Flexible template for custom messages
All templates feature:
- Responsive design
- Inline CSS for email client compatibility
- Dynamic content placeholders
- Professional styling
- Plain text fallbacks
- TLS/SSL Encryption: All SMTP connections encrypted
- Environment Variables: Sensitive data stored securely
- Input Validation: Email addresses and content validated
- Sanitization: User inputs sanitized to prevent injection
- Connection Timeouts: Prevents hanging connections
- Error Handling: Secure error messages without exposing internals
- Open the application in your browser
- Fill out the test form with recipient details
- Choose an email template
- Click "Send Email"
Visit /api/send-email (GET request) to check SMTP service status.
```javascript const response = await fetch('/api/send-email', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ to: 'recipient@example.com', subject: 'Test Email', name: 'John Doe', template: 'welcome' }) }) ```
The service handles various error scenarios:
- SMTP authentication failures
- Connection timeouts
- Invalid email addresses
- Server downtime
- Rate limiting
- Push code to GitHub
- Connect repository to Vercel
- Add environment variables in Vercel dashboard
- Deploy
Ensure all SMTP environment variables are set in your production environment.
- Health check endpoint:
GET /api/send-email - Console logging for sent emails
- Error tracking and reporting
- Add template case in
lib/email-templates.ts - Create HTML and text versions
- Update TypeScript types
Add new provider configurations in the .env.example file and update documentation.
- Use App Passwords: For Gmail and other providers requiring 2FA
- Verify Domains: Set up SPF, DKIM, and DMARC records
- Monitor Reputation: Keep track of bounce rates and spam reports
- Rate Limiting: Implement rate limiting for production use
- Logging: Monitor email sending for debugging and analytics
Authentication Failed
- Verify SMTP credentials
- Check if 2FA is enabled (Gmail requires App Password)
- Ensure correct SMTP host and port
Connection Timeout
- Check firewall settings
- Verify SMTP host is accessible
- Try different ports (587, 465, 25)
Emails Not Delivered
- Check spam folder
- Verify sender reputation
- Set up proper DNS records (SPF, DKIM, DMARC)
MIT License - feel free to use this in your projects!