You bring up Postal as a self-hosted Mailgun replacement: clone the repo, point a domain at it, generate the credentials, hand the SMTP host and port to the application team. Receipts ship, password resets ship, things look fine. Two months in the volume scales, somebody decides “the marketing newsletter should go through it too,” the sender reputation collapses, and Amazon SES’s outbound starts looking attractive again. The MTA wasn’t the problem — the problem is that the box was deployed as if it were Postfix on a single VM, with no DKIM rotation discipline, no separation between transactional and bulk traffic, and click-tracking enabled globally so every receipt was rewriting every link to an opaque redirector that some receivers flagged as obfuscation.
What’s happening
Postal is a transactional MTA. It is built for password resets, receipts, OTP codes, and signed notifications — high deliverability on low volume per message, with strong observability into bounces and complaints. To stay clean it needs: rDNS aligned with the sending hostname; one DKIM key per mail domain (Postal generates them, you publish them); SPF that authorises the Postal IP; a separate IP or at minimum a separate Postal server (Postal’s term for a sending profile) for any bulk traffic, never mixing receipts and newsletters under the same DKIM d= ; click-tracking and open-tracking disabled by default for transactional servers — these break SPF alignment via the tracking domain unless that domain is itself authenticated; webhook delivery for bounces/complaints wired to whatever creates and disables user accounts so a hard bounce removes the address. The MariaDB and RabbitMQ backends must be bound to localhost only — Postal talks to them locally and there is no reason for them to be reachable from the network.
How to verify
After install, the host listeners should be tightly scoped:
ss -lntp | grep -E ':(25|80|443|587|3306|5672|15672|25025)\b'
# 0.0.0.0:25 postal-smtp
# 0.0.0.0:587 postal-smtp
# 0.0.0.0:443 nginx
# 0.0.0.0:80 nginx
# 127.0.0.1:3306 mariadbd
# 127.0.0.1:5672 rabbitmq
# 127.0.0.1:25025 postal-internal
MariaDB and RabbitMQ on 127.0.0.1 only. Then confirm STARTTLS on submission and the Let’s Encrypt cert on the admin UI:
openssl s_client -starttls smtp -crlf -connect postal.example.com:587 -servername postal.example.com </dev/null 2>/dev/null | grep -E 'subject=|issuer='
curl -sI https://postal.example.com/ | head -5
DKIM lookup for a specific Postal server after you create it in the UI:
dig +short TXT postal-<token>._domainkey.example.com
If the TXT record returns nothing, the DKIM was generated inside Postal but never published in DNS, and every receiver is rejecting alignment.
The fix
Save the script below as /root/setup-postal-ubuntu22.sh, then run it. It performs the full installer flow on a fresh Ubuntu 22.04 VM: apt update, kernel/network tuning, file limits, removes postfix and exim4 from the host so nothing competes for port 25, hardens SSH while keeping root key access, configures UFW with the right rules, installs MariaDB 10.11 + RabbitMQ + Docker CE + compose plugin (Postal v3 ships as Docker images), pulls the official Postal helper, generates secrets, writes postal.yml with localhost-only backends and S3-compatible message store wiring, brings the stack up, generates a Let’s Encrypt cert for the admin UI with nginx, configures fail2ban for SSH and SMTP AUTH brute-force, and prints the bootstrap admin credentials at the end.
#!/usr/bin/env bash
set -euo pipefail
### Ubuntu 22.04 Postal transactional MTA clean VM installer
### Keeps root SSH key login enabled
### Disables SSH password login
### Enables automatic security updates
### Installs MariaDB + RabbitMQ + Docker CE + Postal v3
### No local backups; assumes VM-level backup
### Reboot remains manual
if [[ "$(id -u)" -ne 0 ]]; then
echo "Run as root."
exit 1
fi
: "${POSTAL_HOSTNAME:?Set POSTAL_HOSTNAME, e.g. postal.example.com}"
: "${POSTAL_MAIL_HOSTNAME:?Set POSTAL_MAIL_HOSTNAME, e.g. send.example.com}"
: "${LETSENCRYPT_EMAIL:?Set LETSENCRYPT_EMAIL}"
: "${TIMEZONE:=America/Toronto}"
export DEBIAN_FRONTEND=noninteractive
echo
echo "========================================"
echo "Postal Ubuntu 22.04 Setup"
echo "Web hostname: ${POSTAL_HOSTNAME}"
echo "Mail hostname: ${POSTAL_MAIL_HOSTNAME}"
echo "========================================"
echo
echo "==> Updating base OS"
apt-get update
apt-get -y upgrade
echo "==> Installing base packages"
apt-get -y install \
vim curl wget gnupg ca-certificates chrony \
fail2ban unattended-upgrades \
lsof tcpdump dnsutils \
ufw jq git \
python3 python3-pip \
apt-transport-https software-properties-common
timedatectl set-ntp true
timedatectl set-timezone "${TIMEZONE}"
echo "==> Removing host MTAs that would collide with port 25"
apt-get -y purge postfix exim4 exim4-base exim4-config sendmail-bin || true
echo "==> Applying kernel/network tuning"
cat > /etc/sysctl.d/99-postal.conf <<'SYSCTL'
net.core.default_qdisc = fq
net.ipv4.tcp_congestion_control = bbr
net.core.somaxconn = 4096
net.core.netdev_max_backlog = 250000
net.ipv4.tcp_max_syn_backlog = 8192
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_fin_timeout = 15
net.ipv4.ip_local_port_range = 10240 65535
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
kernel.dmesg_restrict = 1
kernel.kptr_restrict = 2
fs.file-max = 2097152
SYSCTL
modprobe tcp_bbr || true
echo tcp_bbr > /etc/modules-load.d/bbr.conf
sysctl --system
cat > /etc/security/limits.d/99-postal.conf <<'LIMITS'
* soft nofile 64000
* hard nofile 64000
root soft nofile 64000
root hard nofile 64000
LIMITS
echo "==> Hardening SSH while keeping root SSH key login enabled"
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak.$(date +%F-%H%M%S)
set_sshd_option() {
local key="$1"
local value="$2"
if grep -qE "^[#[:space:]]*${key}[[:space:]]+" /etc/ssh/sshd_config; then
sed -i "s|^[#[:space:]]*${key}[[:space:]].*|${key} ${value}|" /etc/ssh/sshd_config
else
echo "${key} ${value}" >> /etc/ssh/sshd_config
fi
}
set_sshd_option PermitRootLogin prohibit-password
set_sshd_option PasswordAuthentication no
set_sshd_option PubkeyAuthentication yes
set_sshd_option KbdInteractiveAuthentication no
set_sshd_option X11Forwarding no
set_sshd_option ClientAliveInterval 300
set_sshd_option ClientAliveCountMax 2
set_sshd_option MaxAuthTries 4
sshd -t
systemctl restart sshd
echo "==> Configuring UFW"
ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw allow 25/tcp
ufw allow 587/tcp
ufw allow 80/tcp
ufw allow 443/tcp
yes | ufw enable
echo "==> Configuring unattended-upgrades for security only"
cat > /etc/apt/apt.conf.d/52unattended-upgrades-local <<'UA'
Unattended-Upgrade::Allowed-Origins {
"${distro_id}:${distro_codename}-security";
"${distro_id}ESMApps:${distro_codename}-apps-security";
"${distro_id}ESM:${distro_codename}-infra-security";
};
Unattended-Upgrade::Automatic-Reboot "false";
UA
cat > /etc/apt/apt.conf.d/20auto-upgrades <<'AAU'
APT::Periodic::Update-Package-Lists "1";
APT::Periodic::Unattended-Upgrade "1";
AAU
echo "==> Installing MariaDB 10.11 (localhost-bound)"
curl -fsSL https://mariadb.org/mariadb_release_signing_key.pgp \
| gpg --dearmor -o /usr/share/keyrings/mariadb-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/mariadb-archive-keyring.gpg] https://mirror.its.dal.ca/mariadb/repo/10.11/ubuntu jammy main" \
> /etc/apt/sources.list.d/mariadb.list
apt-get update
apt-get -y install mariadb-server mariadb-client
cat > /etc/mysql/mariadb.conf.d/99-postal.cnf <<'MARIADB'
[mysqld]
bind-address = 127.0.0.1
max_connections = 300
innodb_buffer_pool_size = 1G
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
MARIADB
systemctl restart mariadb
POSTAL_DB_PASSWORD="$(openssl rand -hex 24)"
mysql --protocol=socket -uroot <<SQL
CREATE DATABASE IF NOT EXISTS postal CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER IF NOT EXISTS 'postal'@'127.0.0.1' IDENTIFIED BY '${POSTAL_DB_PASSWORD}';
GRANT ALL ON \`postal%\`.* TO 'postal'@'127.0.0.1';
GRANT ALL ON postal.* TO 'postal'@'127.0.0.1';
GRANT ALL ON *.* TO 'postal'@'127.0.0.1' WITH GRANT OPTION;
FLUSH PRIVILEGES;
SQL
echo "==> Installing RabbitMQ (localhost-bound)"
apt-get -y install rabbitmq-server
mkdir -p /etc/rabbitmq
cat > /etc/rabbitmq/rabbitmq.conf <<'RMQ'
listeners.tcp.local = 127.0.0.1:5672
loopback_users.guest = false
RMQ
systemctl enable --now rabbitmq-server
systemctl restart rabbitmq-server
RMQ_PASSWORD="$(openssl rand -hex 24)"
rabbitmqctl add_vhost /postal || true
rabbitmqctl add_user postal "${RMQ_PASSWORD}" 2>/dev/null \
|| rabbitmqctl change_password postal "${RMQ_PASSWORD}"
rabbitmqctl set_permissions -p /postal postal ".*" ".*" ".*"
echo "==> Installing Docker CE + compose plugin"
install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg
chmod a+r /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu jammy stable" \
> /etc/apt/sources.list.d/docker.list
apt-get update
apt-get -y install docker-ce docker-ce-cli containerd.io docker-compose-plugin
systemctl enable --now docker
echo "==> Fetching Postal helper"
git clone https://github.com/postalserver/install /opt/postal-install || true
ln -sf /opt/postal-install/bin/postal /usr/bin/postal
mkdir -p /opt/postal/config
SIGNING_KEY="$(openssl genrsa 2048 2>/dev/null)"
SECRET_KEY="$(openssl rand -hex 32)"
cat > /opt/postal/config/postal.yml <<YAML
version: 2
postal:
web_hostname: ${POSTAL_HOSTNAME}
smtp_hostname: ${POSTAL_MAIL_HOSTNAME}
use_ip_pools: false
secret_key: ${SECRET_KEY}
web_server:
bind_address: 127.0.0.1
port: 5000
main_db:
host: 127.0.0.1
username: postal
password: ${POSTAL_DB_PASSWORD}
database: postal
message_db:
host: 127.0.0.1
username: postal
password: ${POSTAL_DB_PASSWORD}
prefix: postal
rabbitmq:
host: 127.0.0.1
port: 5672
username: postal
password: ${RMQ_PASSWORD}
vhost: /postal
dns:
mx_records:
- ${POSTAL_MAIL_HOSTNAME}
smtp_server_hostname: ${POSTAL_MAIL_HOSTNAME}
spf_include: ${POSTAL_MAIL_HOSTNAME}
return_path_domain: rp.${POSTAL_MAIL_HOSTNAME#*.}
route_domain: routes.${POSTAL_MAIL_HOSTNAME#*.}
track_domain: track.${POSTAL_MAIL_HOSTNAME#*.}
smtp_relays: []
smtp_server:
port: 25
tls_enabled: true
proxy_protocol: false
YAML
echo "==> Writing signing key"
mkdir -p /opt/postal/config
echo "${SIGNING_KEY}" > /opt/postal/config/signing.key
chmod 600 /opt/postal/config/signing.key
echo "==> Initialising Postal"
postal initialize
postal make-user --first-name Admin --last-name User --email "${LETSENCRYPT_EMAIL}" --password "$(openssl rand -hex 16 | tee /root/.postal_admin_password)"
postal start
echo "==> Installing nginx + Let's Encrypt"
apt-get -y install nginx certbot python3-certbot-nginx
cat > /etc/nginx/sites-available/postal.conf <<NGINX
server {
listen 80;
server_name ${POSTAL_HOSTNAME};
location /.well-known/acme-challenge/ { root /var/www/html; }
location / { return 301 https://\$host\$request_uri; }
}
server {
listen 443 ssl http2;
server_name ${POSTAL_HOSTNAME};
# placeholder; certbot will rewrite these
ssl_certificate /etc/letsencrypt/live/${POSTAL_HOSTNAME}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${POSTAL_HOSTNAME}/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
client_max_body_size 50m;
location / {
proxy_pass http://127.0.0.1:5000;
proxy_set_header Host \$host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
}
}
NGINX
ln -sf /etc/nginx/sites-available/postal.conf /etc/nginx/sites-enabled/postal.conf
rm -f /etc/nginx/sites-enabled/default
mkdir -p /var/www/html
# certbot will provision the cert and reload nginx
certbot --nginx -n --agree-tos -m "${LETSENCRYPT_EMAIL}" -d "${POSTAL_HOSTNAME}"
systemctl reload nginx
echo "==> Configuring fail2ban"
mkdir -p /etc/fail2ban/jail.d /etc/fail2ban/filter.d
cat > /etc/fail2ban/jail.d/sshd.local <<'FAIL2BAN_SSH'
[sshd]
enabled = true
port = ssh
backend = systemd
maxretry = 4
findtime = 10m
bantime = 1h
FAIL2BAN_SSH
cat > /etc/fail2ban/filter.d/postal-smtp-auth.conf <<'F2B'
[Definition]
failregex = ^.*authentication failed.*ip=<HOST>.*$
ignoreregex =
F2B
cat > /etc/fail2ban/jail.d/postal.local <<'FAIL2BAN_POSTAL'
[postal-smtp-auth]
enabled = true
filter = postal-smtp-auth
logpath = /opt/postal/log/*.log
maxretry = 6
findtime = 10m
bantime = 24h
banaction = iptables-multiport
port = smtp,submission
FAIL2BAN_POSTAL
systemctl enable --now fail2ban
echo "==> Setting systemd LimitNOFILE for docker"
mkdir -p /etc/systemd/system/docker.service.d
cat > /etc/systemd/system/docker.service.d/override.conf <<'DOCKER_LIMITS'
[Service]
LimitNOFILE=64000
DOCKER_LIMITS
systemctl daemon-reload
systemctl restart docker
echo "==> Waiting for SMTP listener"
for i in {1..60}; do
if ss -lntp | grep -q ':25 '; then
break
fi
sleep 2
done
echo
echo "========================================"
echo "DONE"
echo "========================================"
echo
echo "Listeners:"
ss -lntp | grep -E ':(25|80|443|587|3306|5672)\b' || true
echo
echo "Services:"
systemctl is-active mariadb rabbitmq-server docker nginx fail2ban || true
echo
echo "Postal containers:"
postal status || docker ps --filter name=postal
echo
echo "Web UI:"
echo "https://${POSTAL_HOSTNAME}/"
echo "Admin email: ${LETSENCRYPT_EMAIL}"
echo "Admin password: $(cat /root/.postal_admin_password)"
echo
echo "Next: in the admin UI, create an Organization > Server > Domain. Postal will display"
echo "the DKIM TXT record (selector postal-<token>._domainkey.example.com) and the SPF"
echo "include directive (include:${POSTAL_MAIL_HOSTNAME}). Publish both before sending."
echo
echo "Suggested DNS scaffolding:"
echo " A ${POSTAL_HOSTNAME} -> <this server IP>"
echo " A ${POSTAL_MAIL_HOSTNAME} -> <this server IP>"
echo " MX rp.${POSTAL_MAIL_HOSTNAME#*.} -> ${POSTAL_MAIL_HOSTNAME}"
echo " TXT _dmarc.example.com -> v=DMARC1; p=none; rua=mailto:dmarc@example.com"
echo
echo "Final step: confirm rDNS (PTR) for the public IP resolves to ${POSTAL_MAIL_HOSTNAME}"
Make it executable and run it:
chmod 700 /root/setup-postal-ubuntu22.sh
POSTAL_HOSTNAME=postal.example.com \
POSTAL_MAIL_HOSTNAME=send.example.com \
LETSENCRYPT_EMAIL=ops@example.com \
/root/setup-postal-ubuntu22.sh
In the admin UI, create the Organization, then create one Server for transactional traffic and a separate Server for anything bulk. Disable click-tracking and open-tracking on the transactional Server — these rewrite every link through a tracking domain and break SPF alignment for receivers that don’t expand the redirector. For the transactional Server, set the Send Limit conservatively (a few hundred per hour initially) and only raise it once Postmaster Tools at Gmail and SNDS at Microsoft show a clean reputation. Wire the bounce/complaint webhook to whatever creates accounts in the application so a hard bounce flags or removes the address automatically.
Self-hosted transactional mail only pays off when somebody monitors the deliverability metrics weekly. Stack Harbor runs Postal under monitoring and support with Gmail and Microsoft postmaster feedback wired in.