Deploying Emailwiz
Introduction
Emailwiz is a bash script created by Luke Smith that automates the setup of a fully functional mail server on a Debian-based system. It configures Postfix for sending email, Dovecot for IMAP access, SpamAssassin for spam filtering, and OpenDKIM for email authentication. The result is a self-hosted email solution that rivals commercial providers in functionality.
Key highlights of Emailwiz:
- Complete Mail Stack: Installs and configures Postfix, Dovecot, SpamAssassin, and OpenDKIM in one automated process
- DKIM Signing: Automatically generates DKIM keys for email authentication and improved deliverability
- Spam Filtering: SpamAssassin integration to filter unwanted messages
- IMAP Support: Full IMAP access via Dovecot for desktop and mobile email clients
- Secure by Default: TLS encryption for all mail transport
- Minimal Dependencies: Runs on a standard Debian installation without complex requirements
- User Management: Simple Unix user-based email account management
- Open Source: Licensed under GPLv3 with active community development
This guide walks through deploying a containerized mail server based on Emailwiz principles on Klutch.sh, including DNS configuration, persistent storage setup, and production considerations.
Why Deploy Emailwiz on Klutch.sh
Deploying a mail server on Klutch.sh provides several advantages:
Simplified Infrastructure: Klutch.sh handles container orchestration, letting you focus on mail server configuration rather than server management.
Persistent Storage: Attach volumes for mail storage, ensuring emails survive container restarts and redeployments.
Static IP Access: Mail servers require consistent IP addresses for proper DNS configuration and reputation building.
Automatic TLS: Klutch.sh provides TLS certificates for your mail server’s web interfaces automatically.
Environment Variables: Securely store sensitive configuration like database passwords and API keys.
Scalable Resources: Adjust CPU and memory allocation based on your email volume requirements.
Prerequisites
Before deploying Emailwiz on Klutch.sh, ensure you have:
- A Klutch.sh account
- A GitHub account with a repository for your mail server configuration
- A domain name with access to DNS settings
- Understanding of email DNS records (MX, SPF, DKIM, DMARC)
- Basic familiarity with Docker and mail server concepts
Understanding Mail Server Architecture
A complete mail server requires several components working together:
Postfix (MTA): The Mail Transfer Agent handles sending and receiving email between servers using SMTP protocol.
Dovecot (MDA): The Mail Delivery Agent provides IMAP and POP3 access for email clients to retrieve messages.
SpamAssassin: Analyzes incoming mail and scores messages for spam likelihood.
OpenDKIM: Signs outgoing mail with DKIM signatures to improve deliverability and prove authenticity.
Certbot: Manages TLS certificates for encrypted mail transport.
Preparing Your Repository
Create a GitHub repository with your mail server Dockerfile configuration.
Repository Structure
emailwiz-deploy/├── Dockerfile├── config/│ └── postfix/│ └── main.cf.template├── scripts/│ └── entrypoint.sh└── .dockerignoreCreating the Dockerfile
Create a Dockerfile that sets up the mail server components:
FROM debian:bookworm-slim
# Install mail server componentsRUN apt-get update && apt-get install -y \ postfix \ postfix-pcre \ dovecot-imapd \ dovecot-lmtpd \ spamassassin \ spamc \ opendkim \ opendkim-tools \ certbot \ ca-certificates \ curl \ supervisor \ && rm -rf /var/lib/apt/lists/*
# Set environment variablesENV DOMAIN=${DOMAIN}ENV HOSTNAME=${HOSTNAME}
# Create mail directoriesRUN mkdir -p /var/mail/vhosts \ && mkdir -p /var/spool/postfix \ && mkdir -p /etc/opendkim/keys
# Copy configuration templatesCOPY config/ /etc/mail-config/COPY scripts/entrypoint.sh /entrypoint.shRUN chmod +x /entrypoint.sh
# Expose mail portsEXPOSE 25 587 993 143
ENTRYPOINT ["/entrypoint.sh"]Environment Variables Reference
| Variable | Required | Description |
|---|---|---|
DOMAIN | Yes | Primary mail domain (e.g., example.com) |
HOSTNAME | Yes | Mail server hostname (e.g., mail.example.com) |
ADMIN_EMAIL | Yes | Administrator email address |
TLS_CERT_PATH | No | Path to TLS certificate |
TLS_KEY_PATH | No | Path to TLS private key |
Deploying Emailwiz on Klutch.sh
- Port 25 (SMTP)
- Port 587 (Submission)
- Port 993 (IMAPS)
- Port 143 (IMAP)
Configure DNS Records
Before deployment, set up the required DNS records for your domain:
| Record Type | Name | Value |
|---|---|---|
| A | Your server IP | |
| MX | @ | mail.yourdomain.com (priority 10) |
| TXT | @ | v=spf1 mx -all |
| TXT | _dmarc | v=DMARC1; p=quarantine; rua=mailto:admin@yourdomain.com |
DKIM records will be generated after initial setup.
Push Your Repository to GitHub
Initialize and push your configuration repository to GitHub for Klutch.sh integration.
Create a New Project on Klutch.sh
Navigate to the Klutch.sh dashboard and create a new project named “emailwiz” or “mail-server”.
Create a New App
Within your project, create a new app and connect your GitHub repository containing the Dockerfile.
Configure Network Settings
Mail servers require specific ports:
Configure these in your deployment settings.
Set Environment Variables
Add the required environment variables:
| Variable | Value |
|---|---|
DOMAIN | yourdomain.com |
HOSTNAME | mail.yourdomain.com |
ADMIN_EMAIL | admin@yourdomain.com |
Attach Persistent Volumes
| Mount Path | Size | Purpose |
|---|---|---|
/var/mail | 50+ GB | Email storage |
/etc/opendkim/keys | 100 MB | DKIM keys |
/var/log/mail | 5 GB | Mail logs |
Deploy Your Application
Click Deploy to build and start your mail server. Klutch.sh will build the container and provision resources.
Complete DKIM Setup
After deployment, retrieve your DKIM public key and add it as a TXT record in your DNS.
Post-Deployment Configuration
Adding Email Users
Create email accounts by adding system users to the mail server. Access the container and use standard Unix user management tools.
Testing Mail Delivery
Send test emails to verify:
- Outgoing mail delivery
- Incoming mail reception
- Spam filtering
- DKIM signatures
Use tools like Mail-Tester to verify your configuration.
Troubleshooting
Mail Not Sending
- Verify DNS records are properly configured
- Check that port 25 is not blocked
- Review Postfix logs for errors
DKIM Failures
- Ensure DKIM DNS record matches generated key
- Verify OpenDKIM service is running
- Check key permissions
Spam Classification Issues
- Adjust SpamAssassin thresholds
- Update spam rules regularly
- Review spam logs for false positives
Additional Resources
Conclusion
Deploying a mail server with Emailwiz principles on Klutch.sh provides a self-hosted email solution with full control over your communications. While mail server administration requires ongoing attention to deliverability and security, the combination of automated setup and Klutch.sh’s infrastructure simplifies the operational burden.