On this page
- Clear up outbound mail and PTR first
- What does this setup include and which releases does it target?
- Set the hostname and DNS records
- How do I install Postfix and the certificate?
- Turn on submission port 587
- How do I configure Dovecot for Maildir and logins?
- Add Roundcube webmail
- Open the firewall ports
- How do I check delivery end to end?
- Questions
Clear up outbound mail and PTR first
Send a ticket to support before configuring anything and ask two things: whether direct SMTP on port 25 is open for your server, and to set reverse DNS (PTR) for 198.51.100.24 and 2001:db8:4f2a::24 to mail.example.net. Port 25 is not promised on our network, and receiving systems check PTR closely. If direct delivery is not possible, the server below still receives mail and serves IMAP; you only add a relayhost so outgoing messages travel over authenticated port 587, as shown in the SMTP relay guide.
What does this setup include and which releases does it target?
It targets Ubuntu 24.04, Ubuntu 22.04 and Debian 12, which all ship Dovecot 2.3. Debian 13 ships Dovecot 2.4, whose configuration syntax changed, so the Dovecot section here does not apply to it as written. Accounts are ordinary Linux users, which keeps the design simple for a handful of mailboxes. Components:
- Postfix receives mail on 25 and accepts authenticated submission on 587.
- Dovecot serves IMAP on 993 and checks passwords for Postfix.
- Roundcube gives a webmail interface over HTTPS.
A1-2 handles a few users; choose A2-4 if you also add SpamAssassin. Start from a fresh image and a sudo user (see create a sudo user).
Set the hostname and DNS records
Name the server after its mail host and publish matching records.
sudo hostnamectl set-hostname mail.example.net
echo "198.51.100.24 mail.example.net mail" | sudo tee -a /etc/hosts
hostname -fIn DNS, create an A and AAAA record for mail.example.net and an MX record for example.net pointing at it. Add SPF, DKIM and DMARC as described in SPF, DKIM and DMARC records before sending real mail.
How do I install Postfix and the certificate?
Install the packages, choosing Internet Site and example.net as the system mail name when Postfix asks.
sudo apt update
sudo apt install postfix dovecot-imapd apache2 certbot python3-certbot-apache
postconf mail_version
dovecot --version
sudo certbot --apache -d mail.example.netCertbot uses Apache, which Roundcube needs anyway, and stores the files under /etc/letsencrypt/live/mail.example.net/. Now configure Postfix with postconf -e, which edits main.cf safely:
sudo postconf -e "myhostname = mail.example.net"
sudo postconf -e "mydestination = \$myhostname, example.net, localhost"
sudo postconf -e "home_mailbox = Maildir/"
sudo postconf -e "smtpd_tls_cert_file = /etc/letsencrypt/live/mail.example.net/fullchain.pem"
sudo postconf -e "smtpd_tls_key_file = /etc/letsencrypt/live/mail.example.net/privkey.pem"
sudo postconf -e "smtpd_tls_security_level = may"
sudo postconf -e "smtp_tls_security_level = may"
sudo postconf -e "smtpd_sasl_type = dovecot"
sudo postconf -e "smtpd_sasl_path = private/auth"
sudo postconf -e "smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"Turn on submission port 587
Add a submission service to master.cf that demands TLS and a login. The postconf -M and -P forms avoid hand editing:
sudo postconf -M submission/inet="submission inet n - y - - smtpd"
sudo postconf -P "submission/inet/syslog_name=postfix/submission"
sudo postconf -P "submission/inet/smtpd_tls_security_level=encrypt"
sudo postconf -P "submission/inet/smtpd_sasl_auth_enable=yes"
sudo postconf -P "submission/inet/smtpd_client_restrictions=permit_sasl_authenticated,reject"
sudo postfix check
sudo systemctl restart postfixNo output from postfix check means the configuration parsed cleanly. Mail clients and Roundcube will now send through 587 with a username and password.
How do I configure Dovecot for Maildir and logins?
Put your changes in one file that loads after the defaults, so package upgrades never overwrite them.
sudo tee /etc/dovecot/conf.d/99-local.conf >/dev/null <<EOF
mail_location = maildir:~/Maildir
disable_plaintext_auth = yes
auth_mechanisms = plain login
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.net/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.net/privkey.pem
ssl_min_protocol = TLSv1.2
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}
EOF
sudo doveconf -n | head -n 20
sudo systemctl restart dovecotThe unix_listener creates the socket Postfix reads through smtpd_sasl_path. Create a mailbox user (the account name becomes the address deploy@example.net):
sudo adduser deployAdd Roundcube webmail
Install Roundcube from the distribution with an SQLite database; when the dbconfig dialog appears, accept it and choose sqlite3.
sudo apt install roundcube roundcube-sqlite3
sudo a2enconf roundcube
sudo systemctl reload apache2Open /etc/roundcube/apache.conf and make sure the Alias /roundcube line is active (remove the leading # if needed), then reload Apache. Point Roundcube at your own services in /etc/roundcube/config.inc.php:
$config['imap_host'] = 'ssl://mail.example.net:993';
$config['smtp_host'] = 'tls://mail.example.net:587';
$config['smtp_user'] = '%u';
$config['smtp_pass'] = '%p';
$config['product_name'] = 'Example Mail';Visit https://mail.example.net/roundcube/ and sign in as deploy. If you prefer a lighter interface, SnappyMail connects to the same IMAP and submission ports.
Open the firewall ports
Allow only the services this server offers:
sudo ufw allow OpenSSH
sudo ufw allow 25,587,993/tcp
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status numberedPort 80 stays open so certbot can renew. More on rules and safe enabling is in the UFW guide. Adding Fail2ban jails for postfix-sasl and dovecot stops password guessing.
How do I check delivery end to end?
Test locally, then outward.
sudo ss -tlnp | grep -E ":(25|587|993) "
echo "first local test" | mail -s "hello" deploy@example.net
ls ~deploy/Maildir/new/
sudo tail -n 30 /var/log/mail.logThe mail command comes from bsd-mailx or mailutils. A file in Maildir/new proves local delivery. Next, send from an outside mailbox to deploy@example.net and reply from Roundcube. A remote reply that sits in mailq with a timeout to port 25 means outbound 25 is closed: add the relayhost settings and send again over 587. Finally, add a deploy hook such as systemctl reload postfix dovecot apache2 under /etc/letsencrypt/renewal-hooks/deploy/ so renewed certificates load automatically.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Postfix, Dovecot and Roundcube by hand
Do I need port 25 open to receive mail?
Inbound 25 is what other servers use to reach you, and it is separate from outbound 25. Ask support by ticket about outbound 25, and use an authenticated relay on 587 for sending if it is closed.
Can I host several domains with this design?
Add each domain to mydestination and every user receives mail at each of them. For separate users per domain, move to virtual mailboxes or use iRedMail.
Why is Debian 13 not covered?
Debian 13 ships Dovecot 2.4 with a reworked configuration format. Use Debian 12 or Ubuntu 24.04 for this guide, or adapt the Dovecot part with the 2.4 documentation.
Where do I request reverse DNS?
Open a support ticket with both IP addresses and the hostname mail.example.net.
How do I add a mailbox later?
Run sudo adduser name. The Maildir folder is created on first delivery, and the user can log in to IMAP and Roundcube right away.