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
- MX record pointing to your deployment
- SPF record for sender authentication
- DKIM keys for email signing
- DMARC policy record
Configure DNS Records
Before deploying, set up DNS records for your email domain:
Create Your Dockerfile
Create a Dockerfile in your repository:
FROM alpine:latest
# Install OpenSMTPDRUN apk add --no-cache opensmtpd opensmtpd-extras
# Create directoriesRUN mkdir -p /var/spool/smtpd /var/mail /etc/mail
# Copy configurationCOPY smtpd.conf /etc/smtpd/smtpd.conf
# Set permissionsRUN 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 TLSpki mail.example.com cert "/etc/ssl/mail.crt"pki mail.example.com key "/etc/ssl/mail.key"
# Tablestable aliases file:/etc/mail/aliases
# Listen directiveslisten on 0.0.0.0 port 25 tls pki mail.example.comlisten on 0.0.0.0 port 587 tls-require pki mail.example.com auth
# Action definitionsaction "local" mbox alias <aliases>action "relay" relay
# Match rulesmatch 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:
| Port | Purpose |
|---|---|
| 25 | SMTP for receiving mail |
| 587 | Submission port for sending |
Attach Persistent Volumes
Add persistent storage:
| Mount Path | Recommended Size | Purpose |
|---|---|---|
/var/spool/smtpd | 5 GB | Mail queue |
/var/mail | 10 GB | Local mailboxes |
/etc/ssl | 100 MB | TLS certificates |
Deploy Your Application
Click Deploy to build and launch your OpenSMTPD instance.
Test Email Delivery
Send test emails to verify configuration and delivery.