Skip to main content
Skip to main content

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.

📧email

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-service

Environment Variables

EMAIL_PROVIDERRequired

Email service provider to use

Example: gmail
EMAIL_FROM_NAMERequired

Default sender name for all emails

Example: Your App Name
EMAIL_FROM_ADDRESSRequired

Default sender email address

Example: noreply@yourapp.com
Complete .env example:
EMAIL_PROVIDER=gmail
EMAIL_FROM_NAME=Your App Name
EMAIL_FROM_ADDRESS=noreply@yourapp.com

Gmail Integration​

📧email

Gmail Email Service

Send emails through Gmail using App Passwords for secure authentication

Installation

npm run adapter install email-gmail

Environment Variables

EMAIL_PROVIDERRequired

Set to 'gmail' to use Gmail service

Example: gmail
GMAIL_USERRequired

Your Gmail email address

Example: your-email@gmail.com
GMAIL_APP_PASSWORDRequired

Gmail App Password (not your regular password)

Example: abcd efgh ijkl mnop
Complete .env example:
EMAIL_PROVIDER=gmail
GMAIL_USER=your-email@gmail.com
GMAIL_APP_PASSWORD=abcd efgh ijkl mnop

SMTP Configuration​

📧email

SMTP Email Service

Connect to any SMTP server for email delivery with full customization options

Installation

npm run adapter install email-smtp

Environment Variables

EMAIL_PROVIDERRequired

Set to 'smtp' to use SMTP service

Example: smtp
SMTP_HOSTRequired

SMTP server hostname

Example: smtp.yourdomain.com
SMTP_PORTRequired

SMTP server port

Example: 587
SMTP_SECURE

Use TLS/SSL encryption

Example: true(Default: false)
SMTP_USERRequired

SMTP authentication username

Example: your-email@yourdomain.com
SMTP_PASSWORDRequired

SMTP authentication password

Example: your-smtp-password
Complete .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-password

SendGrid Integration​

📧email

SendGrid Email Service

Professional email delivery service with advanced analytics and deliverability features

Installation

npm run adapter install sendgrid

Environment Variables

EMAIL_PROVIDERRequired

Set to 'sendgrid' to use SendGrid service

Example: sendgrid
SENDGRID_API_KEYRequired

SendGrid API key from your SendGrid dashboard

Example: SG.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SENDGRID_FROM_EMAILRequired

Verified sender email address in SendGrid

Example: noreply@yourdomain.com
Complete .env example:
EMAIL_PROVIDER=sendgrid
SENDGRID_API_KEY=SG.xxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
SENDGRID_FROM_EMAIL=noreply@yourdomain.com

AWS SES Integration​

📧email

AWS SES Email Service

Amazon Simple Email Service for scalable, cost-effective email delivery with AWS integration

Installation

npm run adapter install aws-ses

Environment Variables

EMAIL_PROVIDERRequired

Set to 'aws-ses' to use AWS SES service

Example: aws-ses
AWS_REGIONRequired

AWS region for SES service

Example: us-east-1
AWS_ACCESS_KEY_IDRequired

AWS access key ID with SES permissions

Example: AKIAIOSFODNN7EXAMPLE
AWS_SECRET_ACCESS_KEYRequired

AWS secret access key

Example: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
SES_FROM_EMAILRequired

Verified sender email address in AWS SES

Example: noreply@yourdomain.com
Complete .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.com

Email 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​

  1. Provider Redundancy: Configure multiple email providers for failover
  2. Rate Limiting: Respect provider rate limits to avoid suspension
  3. List Management: Implement proper unsubscribe and bounce handling
  4. Authentication: Set up SPF, DKIM, and DMARC records for better deliverability
  5. Monitoring: Track delivery rates, bounces, and complaints
  6. Testing: Always test email functionality in staging environments
  7. Compliance: Follow CAN-SPAM, GDPR, and other email regulations

Next Steps​

After setting up email services, you might want to: