Email Service Adapters
Mifty provides comprehensive email service adapters that support multiple providers through a unified interface. You can easily switch between different email providers by changing environment variables, making it perfect for development, staging, and production environments.
Universal Email Service Adapter
The universal email service adapter allows you to switch between different email providers without changing your code. Simply configure the provider in your environment variables.
Universal Email Service
Universal email adapter that supports Gmail, SMTP, SendGrid, and AWS SES with provider switching via environment variables
Installation
npm run adapter install email-serviceEnvironment Variables
EMAIL_PROVIDERRequiredEmail service provider to use
gmailEMAIL_FROM_NAMERequiredDefault sender name for all emails
Your App NameEMAIL_FROM_ADDRESSRequiredDefault sender email address
noreply@yourapp.comComplete .env example:
EMAIL_PROVIDER=gmail
EMAIL_FROM_NAME=Your App Name
EMAIL_FROM_ADDRESS=noreply@yourapp.comGmail Integration
Gmail Email Service
Send emails through Gmail using App Passwords for secure authentication
Installation
npm run adapter install email-gmailEnvironment Variables
EMAIL_PROVIDERRequiredSet to 'gmail' to use Gmail service
gmailGMAIL_USERRequiredYour Gmail email address
your-email@gmail.comGMAIL_APP_PASSWORDRequiredGmail App Password (not your regular password)
abcd efgh ijkl mnopComplete .env example:
EMAIL_PROVIDER=gmail
GMAIL_USER=your-email@gmail.com
GMAIL_APP_PASSWORD=abcd efgh ijkl mnopSMTP Configuration
SMTP Email Service
Connect to any SMTP server for email delivery with full customization options
Installation
npm run adapter install email-smtpEnvironment Variables
EMAIL_PROVIDERRequiredSet to 'smtp' to use SMTP service
smtpSMTP_HOSTRequiredSMTP server hostname
smtp.yourdomain.comSMTP_PORTRequiredSMTP server port
587SMTP_SECUREUse TLS/SSL encryption
true(Default: false)SMTP_USERRequiredSMTP authentication username
your-email@yourdomain.comSMTP_PASSWORDRequiredSMTP authentication password
your-smtp-passwordComplete .env example:
EMAIL_PROVIDER=smtp
SMTP_HOST=smtp.yourdomain.com
SMTP_PORT=587
SMTP_SECURE=true
SMTP_USER=your-email@yourdomain.com
SMTP_PASSWORD=your-smtp-passwordSendGrid Integration
SendGrid Email Service
Professional email delivery service with advanced analytics and deliverability features
Installation
npm run adapter install sendgridEnvironment Variables
EMAIL_PROVIDERRequiredSet to 'sendgrid' to use SendGrid service
sendgridSENDGRID_API_KEYRequiredSendGrid API key from your SendGrid dashboard
SG.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxSENDGRID_FROM_EMAILRequiredVerified sender email address in SendGrid
noreply@yourdomain.comComplete .env example:
EMAIL_PROVIDER=sendgrid
SENDGRID_API_KEY=SG.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SENDGRID_FROM_EMAIL=noreply@yourdomain.comAWS SES Integration
AWS SES Email Service
Amazon Simple Email Service for scalable, cost-effective email delivery with AWS integration
Installation
npm run adapter install aws-sesEnvironment Variables
EMAIL_PROVIDERRequiredSet to 'aws-ses' to use AWS SES service
aws-sesAWS_REGIONRequiredAWS region for SES service
us-east-1AWS_ACCESS_KEY_IDRequiredAWS access key ID with SES permissions
AKIAIOSFODNN7EXAMPLEAWS_SECRET_ACCESS_KEYRequiredAWS secret access key
wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEYSES_FROM_EMAILRequiredVerified sender email address in AWS SES
noreply@yourdomain.comComplete .env example:
EMAIL_PROVIDER=aws-ses
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
SES_FROM_EMAIL=noreply@yourdomain.comEmail Testing and Development
Local Email Testing
For development and testing, you can use tools like MailHog or Ethereal Email to capture emails without actually sending them.
# Install MailHog for local email testing
npm install -g mailhog
# Start MailHog server
mailhog
# Configure for local testing
EMAIL_PROVIDER=smtp
SMTP_HOST=localhost
SMTP_PORT=1025
SMTP_SECURE=false
SMTP_USER=""
SMTP_PASSWORD=""
Email Queue Management
For production applications, implement email queuing to handle high volumes and retry failed sends:
// services/email/queue.ts
import { EmailQueue } from '@mifty/email-queue';
const emailQueue = new EmailQueue({
redis: {
host: process.env.REDIS_HOST,
port: process.env.REDIS_PORT
},
concurrency: 5,
retryAttempts: 3
});
// Queue an email
await emailQueue.add('send-email', {
to: 'user@example.com',
subject: 'Welcome',
template: 'welcome',
data: { userName: 'John' }
});
Best Practices
- Provider Redundancy: Configure multiple email providers for failover
- Rate Limiting: Respect provider rate limits to avoid suspension
- List Management: Implement proper unsubscribe and bounce handling
- Authentication: Set up SPF, DKIM, and DMARC records for better deliverability
- Monitoring: Track delivery rates, bounces, and complaints
- Testing: Always test email functionality in staging environments
- Compliance: Follow CAN-SPAM, GDPR, and other email regulations
Next Steps
After setting up email services, you might want to:
- Configure authentication adapters for email-based login
- Set up storage solutions for email attachments
- Implement AI services for email content generation
- Add payment processing for premium email features