Skip to content

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
└── .dockerignore

Creating the Dockerfile

Create a Dockerfile that sets up the mail server components:

FROM debian:bookworm-slim
# Install mail server components
RUN 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 variables
ENV DOMAIN=${DOMAIN}
ENV HOSTNAME=${HOSTNAME}
# Create mail directories
RUN mkdir -p /var/mail/vhosts \
&& mkdir -p /var/spool/postfix \
&& mkdir -p /etc/opendkim/keys
# Copy configuration templates
COPY config/ /etc/mail-config/
COPY scripts/entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
# Expose mail ports
EXPOSE 25 587 993 143
ENTRYPOINT ["/entrypoint.sh"]

Environment Variables Reference

VariableRequiredDescription
DOMAINYesPrimary mail domain (e.g., example.com)
HOSTNAMEYesMail server hostname (e.g., mail.example.com)
ADMIN_EMAILYesAdministrator email address
TLS_CERT_PATHNoPath to TLS certificate
TLS_KEY_PATHNoPath to TLS private key

Deploying Emailwiz on Klutch.sh

    Configure DNS Records

    Before deployment, set up the required DNS records for your domain:

    Record TypeNameValue
    AmailYour server IP
    MX@mail.yourdomain.com (priority 10)
    TXT@v=spf1 mx -all
    TXT_dmarcv=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:

    • Port 25 (SMTP)
    • Port 587 (Submission)
    • Port 993 (IMAPS)
    • Port 143 (IMAP)

    Configure these in your deployment settings.

    Set Environment Variables

    Add the required environment variables:

    VariableValue
    DOMAINyourdomain.com
    HOSTNAMEmail.yourdomain.com
    ADMIN_EMAILadmin@yourdomain.com

    Attach Persistent Volumes

    Mount PathSizePurpose
    /var/mail50+ GBEmail storage
    /etc/opendkim/keys100 MBDKIM keys
    /var/log/mail5 GBMail 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.