Skip to content

📧 Email Platform (Mailu)

Self-hosted email server infrastructure and management

🎯 Overview

The Email Platform is a self-hosted email infrastructure built with Mailu that provides comprehensive email services including SMTP, IMAP, POP3, and webmail. It replaces AWS SES for better control, cost efficiency, and multi-tenant support across the Appgain platform.

🏗️ Architecture

Core Components

  • Mailu Server: All-in-one email solution (Postfix + Dovecot)
  • Web Interface: Mailu webmail and admin interface
  • DNS Management: Automated DNS configuration
  • Email Warm-up: Automated reputation building system
  • Multi-tenant Support: Dedicated or shared email stacks
  • Security Layer: SPF, DKIM, DMARC support

Technology Stack

  • Mailu: Docker-based email stack
  • Postfix: SMTP server
  • Dovecot: IMAP/POP3 server
  • Nginx: Web server and reverse proxy
  • Redis: Session management
  • PostgreSQL: User and domain management

Infrastructure

  • Server: ovh-devops (Email services)
  • Port: 25 (SMTP), 587 (SMTP-TLS), 993 (IMAP-SSL), 995 (POP3-SSL)
  • Environment: Production, Staging, Development
  • Domains: Multiple tenant domains

🔧 Configuration

Server Details

  • Server: ovh-devops
  • SMTP Port: 25, 587 (TLS)
  • IMAP Port: 993 (SSL)
  • POP3 Port: 995 (SSL)
  • Web Interface: https://mail.appgain.io
  • Environment: Production, Staging, Development

Mailu Configuration

# docker-compose.yml
version: '3.8'
services:
  front:
    image: mailu/nginx:1.9
    restart: always
    env_file: mailu.env
    ports:
      - "25:25"
      - "465:465"
      - "587:587"
      - "993:993"
      - "995:995"
      - "443:443"
      - "80:80"
    volumes:
      - "/var/mailu/overrides/:/overrides"
      - "/var/mailu/certs/:/certs"
      - "/var/mailu/webmails/:/webmails"
      - "/var/mailu/filter/:/filter"
      - "/var/mailu/upload/:/upload"

  admin:
    image: mailu/admin:1.9
    restart: always
    env_file: mailu.env
    volumes:
      - "/var/mailu/data/:/data"
      - "/var/mailu/dkim/:/dkim"

  imap:
    image: mailu/dovecot:1.9
    restart: always
    env_file: mailu.env
    volumes:
      - "/var/mailu/mail/:/mail"
      - "/var/mailu/overrides/:/overrides"

  smtp:
    image: mailu/postfix:1.9
    restart: always
    env_file: mailu.env
    volumes:
      - "/var/mailu/mail/:/mail"
      - "/var/mailu/overrides/:/overrides"
      - "/var/mailu/filter/:/filter"

  antispam:
    image: mailu/rspamd:1.9
    restart: always
    env_file: mailu.env
    volumes:
      - "/var/mailu/filter/:/filter"
      - "/var/mailu/dkim/:/dkim"

  webdav:
    image: mailu/radicale:1.9
    restart: always
    env_file: mailu.env

  fetchmail:
    image: mailu/fetchmail:1.9
    restart: always
    env_file: mailu.env

  redis:
    image: redis:alpine
    restart: always
    command: redis-server --appendonly yes

  resolver:
    image: mailu/unbound:1.9
    restart: always
    env_file: mailu.env
    cap_add:
      - NET_ADMIN

Environment Configuration

# mailu.env
SECRET_KEY=your-secret-key
DOMAIN=appgain.io
HOSTNAME=mail.appgain.io
POSTMASTER=postmaster@appgain.io
SITENAME=Appgain Mail
WEBSITE=https://appgain.io
DB_FLAVOR=postgresql
DB_HOST=db
DB_NAME=mailu
DB_USER=mailu
DB_PASS=mailu-password
REDIS_HOST=redis
REDIS_PORT=6379
REDIS_PASSWORD=redis-password

📊 Email Services

SMTP Configuration

# SMTP Settings
SMTP_HOST=mail.appgain.io
SMTP_PORT=587
SMTP_USER=your-email@appgain.io
SMTP_PASS=your-password
SMTP_SECURE=true
SMTP_AUTH=PLAIN

# SMTP Authentication
AUTH_MECHANISM=PLAIN
AUTH_REQUIRED=true
AUTH_USERNAME=your-email@appgain.io
AUTH_PASSWORD=your-password

IMAP Configuration

# IMAP Settings
IMAP_HOST=mail.appgain.io
IMAP_PORT=993
IMAP_USER=your-email@appgain.io
IMAP_PASS=your-password
IMAP_SECURE=true

# IMAP Folders
INBOX=INBOX
SENT=Sent
DRAFTS=Drafts
TRASH=Trash
SPAM=Spam

POP3 Configuration

# POP3 Settings
POP3_HOST=mail.appgain.io
POP3_PORT=995
POP3_USER=your-email@appgain.io
POP3_PASS=your-password
POP3_SECURE=true

🔍 Monitoring & Analytics

Email Metrics

# Email delivery metrics
email_metrics = {
    'total_emails_sent': 1000000,
    'delivery_rate': 99.5,
    'bounce_rate': 0.3,
    'spam_rate': 0.2,
    'active_users': 500,
    'storage_used': '50GB',
    'uptime': 99.9
}

Performance Metrics

  • Delivery Rate: >99% successful delivery
  • Bounce Rate: <1% bounce rate
  • Spam Rate: <0.5% spam rate
  • Uptime: 99.9% service availability

Health Monitoring

# Check email service health
curl -X GET "https://mail.appgain.io/admin/health"

# Check SMTP service
telnet mail.appgain.io 25

# Check IMAP service
telnet mail.appgain.io 993

# Check web interface
curl -X GET "https://mail.appgain.io"

🔒 Security

Email Security

  • SPF Records: Sender Policy Framework
  • DKIM Signing: DomainKeys Identified Mail
  • DMARC Policy: Domain-based Message Authentication
  • TLS Encryption: Transport Layer Security
  • Spam Protection: Rspamd integration

Access Control

  • Multi-Factor Authentication: 2FA support
  • Strong Passwords: Password policy enforcement
  • Rate Limiting: SMTP rate limiting
  • IP Whitelisting: Allowed IP addresses

Data Protection

  • Email Encryption: End-to-end encryption
  • Backup & Recovery: Automated backup systems
  • GDPR Compliance: Data privacy compliance
  • Audit Logging: Complete email audit trail

📈 Performance

Capabilities

  • High Throughput: 10,000+ emails per hour
  • Multi-tenant: Support for multiple domains
  • Scalable: Horizontal scaling support
  • Reliable: 99.9% uptime guarantee

Limitations

  • Storage: 100GB per domain
  • Rate Limits: 1000 emails per hour per user
  • Attachment Size: 25MB maximum
  • Email Size: 50MB maximum

🔗 Integration Examples

Appgain Server Integration

# Email service integration
email_integration = {
    'smtp_config': {
        'host': 'mail.appgain.io',
        'port': 587,
        'username': 'noreply@appgain.io',
        'password': 'SMTP_PASSWORD',
        'use_tls': True,
        'use_ssl': False
    },
    'send_email': {
        'method': 'POST',
        'endpoint': '/api/email/send',
        'data': {
            'to': 'user@example.com',
            'subject': 'Welcome to Appgain',
            'body': 'Welcome message',
            'html': '<h1>Welcome</h1><p>Welcome to Appgain!</p>'
        }
    }
}

Notify Service Integration

# Notify service email integration
notify_email_integration = {
    'email_provider': {
        'type': 'smtp',
        'host': 'mail.appgain.io',
        'port': 587,
        'username': 'notify@appgain.io',
        'password': 'NOTIFY_EMAIL_PASSWORD',
        'secure': True
    },
    'send_notification': {
        'method': 'POST',
        'endpoint': '/notify/email/send',
        'data': {
            'recipient': 'user@example.com',
            'subject': 'Notification',
            'body': 'Notification message',
            'template': 'notification_template'
        }
    }
}

Automator Engine Integration

# Automator email integration
automator_email_integration = {
    'email_action': {
        'type': 'send_email',
        'provider': 'mailu',
        'config': {
            'smtp_host': 'mail.appgain.io',
            'smtp_port': 587,
            'smtp_user': 'automator@appgain.io',
            'smtp_pass': 'AUTOMATOR_EMAIL_PASSWORD'
        }
    },
    'workflow_action': {
        'trigger': 'user_signup',
        'action': 'send_welcome_email',
        'template': 'welcome_email',
        'data': {
            'recipient': '{{user.email}}',
            'subject': 'Welcome to Appgain',
            'variables': {
                'user_name': '{{user.name}}',
                'signup_date': '{{user.createdAt}}'
            }
        }
    }
}

🛠️ Troubleshooting

Common Issues

SMTP Connection Issues

# Test SMTP connection
telnet mail.appgain.io 25

# Test SMTP with authentication
openssl s_client -connect mail.appgain.io:587 -starttls smtp

# Check SMTP logs
tail -f /var/log/mailu/smtp.log

IMAP Connection Issues

# Test IMAP connection
telnet mail.appgain.io 993

# Test IMAP with SSL
openssl s_client -connect mail.appgain.io:993

# Check IMAP logs
tail -f /var/log/mailu/imap.log

Email Delivery Issues

# Check email queue
docker exec mailu_smtp_1 postqueue -p

# Check email logs
docker logs mailu_smtp_1

# Check DNS records
dig TXT appgain.io
dig TXT _dmarc.appgain.io

Debug Commands

# Check Mailu status
docker-compose ps

# Check Mailu logs
docker-compose logs

# Restart Mailu services
docker-compose restart

# Update Mailu
docker-compose pull
docker-compose up -d

📚 Documentation

External Resources

Monitoring Tools

  • Mailu Admin: Web-based administration
  • Grafana Dashboards: Email metrics
  • Prometheus: Performance monitoring
  • ELK Stack: Log analysis

Development Tools

  • GitLab Repository: AppGain Email Platform
  • Postman Collection: Email API testing
  • Development Environment: Docker setup
  • Testing Framework: Email delivery testing
Ask Chehab GPT