Skip to content

Deploying OpenSMTPD

Introduction

OpenSMTPD is a free, secure, and easy-to-configure mail transfer agent (MTA) developed as part of the OpenBSD project. It handles the sending and receiving of email using the Simple Mail Transfer Protocol (SMTP) and is designed with security and simplicity as primary goals.

Originally written for OpenBSD, OpenSMTPD has been ported to Linux and other Unix-like systems. Its clean configuration syntax and focus on security make it an attractive alternative to more complex MTAs like Postfix or Sendmail.

Key features of OpenSMTPD include:

  • Secure by Default: Developed with security-first principles from OpenBSD
  • Simple Configuration: Clean, readable configuration syntax
  • Lightweight: Minimal resource footprint
  • TLS Support: Built-in encryption for secure email transport
  • Virtual Users: Support for virtual domains and users
  • Filtering: Content filtering and spam detection integration
  • Queue Management: Reliable message queuing and delivery
  • Local Delivery: Support for mbox and maildir formats
  • Relay Capability: Forward email through external servers
  • IPv6 Support: Full IPv6 compatibility

This guide walks through deploying OpenSMTPD on Klutch.sh using Docker.

Why Deploy OpenSMTPD on Klutch.sh

Deploying OpenSMTPD on Klutch.sh provides email infrastructure:

Outbound Email: Send transactional emails from your applications.

Simple Setup: Easier to configure than full-featured mail servers.

Persistent Storage: Store mail queues and configurations with persistent volumes.

Custom Domains: Configure your domain for professional email sending.

Note: Running a full email server requires proper DNS configuration (MX, SPF, DKIM, DMARC records) and IP reputation management.

Prerequisites

Before deploying OpenSMTPD on Klutch.sh, ensure you have:

  • A Klutch.sh account
  • A GitHub account with a repository for your deployment
  • A domain with proper DNS configuration for email
  • Understanding of email server requirements and best practices

Deploying OpenSMTPD on Klutch.sh

    Configure DNS Records

    Before deploying, set up DNS records for your email domain:

    • MX record pointing to your deployment
    • SPF record for sender authentication
    • DKIM keys for email signing
    • DMARC policy record

    Create Your Dockerfile

    Create a Dockerfile in your repository:

    FROM alpine:latest
    # Install OpenSMTPD
    RUN apk add --no-cache opensmtpd opensmtpd-extras
    # Create directories
    RUN mkdir -p /var/spool/smtpd /var/mail /etc/mail
    # Copy configuration
    COPY smtpd.conf /etc/smtpd/smtpd.conf
    # Set permissions
    RUN chmod 711 /var/spool/smtpd
    EXPOSE 25 587
    CMD ["smtpd", "-d", "-f", "/etc/smtpd/smtpd.conf"]

    Create Configuration File

    Create smtpd.conf:

    # OpenSMTPD configuration
    # PKI for TLS
    pki mail.example.com cert "/etc/ssl/mail.crt"
    pki mail.example.com key "/etc/ssl/mail.key"
    # Tables
    table aliases file:/etc/mail/aliases
    # Listen directives
    listen on 0.0.0.0 port 25 tls pki mail.example.com
    listen on 0.0.0.0 port 587 tls-require pki mail.example.com auth
    # Action definitions
    action "local" mbox alias <aliases>
    action "relay" relay
    # Match rules
    match from any for domain "example.com" action "local"
    match for any action "relay"

    Push to GitHub

    Commit and push your Dockerfile and configuration to your GitHub repository.

    Create a New Project on Klutch.sh

    Navigate to the Klutch.sh dashboard and create a new project.

    Create and Configure the App

    Create a new app and connect it to your GitHub repository.

    Configure Traffic

    Configure port access for SMTP:

    PortPurpose
    25SMTP for receiving mail
    587Submission port for sending

    Attach Persistent Volumes

    Add persistent storage:

    Mount PathRecommended SizePurpose
    /var/spool/smtpd5 GBMail queue
    /var/mail10 GBLocal mailboxes
    /etc/ssl100 MBTLS certificates

    Deploy Your Application

    Click Deploy to build and launch your OpenSMTPD instance.

    Test Email Delivery

    Send test emails to verify configuration and delivery.

Additional Resources