Offshore 1
$3.09/ month
3 mo $8.346 mo $14.8312 mo $25.95
- 1 vCPU
- 1 GB RAM
- 20 GB NVMe
- 2 TB traffic
Tutorial · Debian 12, Debian 13, Ubuntu 24.04
Set up a mail server that sends and receives for your own domain on a VPS paid only in crypto: Postfix, Dovecot 2.3 or 2.4, a Let's Encrypt certificate that reloads itself, SPF, DKIM, DMARC, tests and backups. Every command follows the official documentation of each program, read on 18 November 2026.
What you build
An email server on a VPS is Postfix to send and receive, Dovecot to serve your mailboxes over IMAP, a TLS certificate, and DNS records: A, MX, SPF, DKIM and DMARC, plus a reverse DNS (PTR) entry for the IP address. This guide covers Debian 12, Debian 13 and Ubuntu 24.04. Debian 13 ships Dovecot 2.4, whose configuration differs from 2.3, so both files are given. Outbound port 25 is open on every Nymhost VPS. Spam is forbidden, and no plan includes backups, so the guide ends with a backup routine you run yourself.
Before you start, check that you have:
example.com and the documentation address 203.0.113.10);Mail moves through the server along three paths:
~/Maildir. Other servers deliver to you, and Postfix writes each message into the user's Maildir folder.~/Maildir. Dovecot serves the same folder over IMAP, and it also checks passwords for Postfix.This VPS mail server setup sticks to Postfix and Dovecot with system users, which is enough for a household or a small team. It leaves out webmail, virus scanning and virtual users; the maintenance section says where to go next. If the server only needs to send (alerts, a website, an application), a send-only Postfix is simpler.
For the plan, Offshore 2 (1 vCPU, 2 GB RAM, 40 GB NVMe, $4.89 a month) is a comfortable start for a few mailboxes. To compare plans and read the port 25 and IP reputation notes first, see which VPS for a mail server.
To set up a mail server on a VPS from a configuration you copied elsewhere, check the Dovecot version first. The system decides it, and Dovecot 2.4 does not accept a 2.3 configuration file. The table lists what each system installs today.
For a new server, take Debian 13 and the Dovecot 2.4 file. Take Debian 12 or Ubuntu 24.04 if you are moving an existing 2.3 configuration and want it to keep working as it is. Ubuntu 22.04, also offered on Nymhost, has Dovecot 2.3.16 and uses the 2.3 file too.
| System | Postfix | Dovecot | OpenDKIM | Dovecot file in this guide |
|---|---|---|---|---|
| Debian 12 (bookworm) | 3.7.11 | 2.3.19.1 | 2.11.0~beta2 | Dovecot 2.3 |
| Debian 13 (trixie) | 3.10.13 | 2.4.1 | 2.11.0~beta2 | Dovecot 2.4 |
| Ubuntu 24.04 LTS (noble) | 3.8.6 | 2.3.21 | 2.11.0~beta2 | Dovecot 2.3 |
| Ubuntu 22.04 LTS (jammy) | 3.6.4 | 2.3.16 | 2.11.0~beta2 | Dovecot 2.3 |
Nymhost also offers AlmaLinux 10 and Rocky Linux 10, which this guide does not cover.
Every VPS email server setup starts with names and ports, because Let's Encrypt, receiving servers and your mail clients all look the server up by name. Run every command in this guide as root.
Set the hostname to mail.example.com; with hostnamectl hostname and a name, it changes the static, pretty and transient hostnames together. Then publish the records in the table at your DNS host. The A record must resolve before Step 2, because Certbot checks it. The DKIM record comes in Step 6.
Each Nymhost VPS also has a routed IPv6 /64. If you configure an IPv6 address on the server and want mail to flow over IPv6, publish an AAAA record for mail.example.com, add an ip6: term to SPF, and ask for reverse DNS on that address as well. Otherwise publish no AAAA record for the mail host; Step 3 keeps Postfix on IPv4.
The firewall below opens 25 (mail from other servers), 80 (certificate issue and renewal, keep it open), 587 (submission) and 993 (IMAPS); 465 and 143 stay closed unless a client needs them. Allow SSH first, on your real SSH port: the ufw manual warns that ufw enable may drop existing connections.
hostnamectl hostname mail.example.com
hostnamectl hostname| Record | Name | Value | When |
|---|---|---|---|
| A | mail.example.com | 203.0.113.10 | Now, before Step 2 |
| MX | example.com | 10 mail.example.com. | Now |
| TXT (SPF) | example.com | v=spf1 mx -all | Now |
| TXT (DMARC) | _dmarc.example.com | v=DMARC1; p=none; rua=mailto:[email protected] | Now, in monitoring mode |
| TXT (DKIM) | mail._domainkey.example.com | v=DKIM1; k=rsa; p=… (from Step 6) | Step 6 |
| PTR | 10.113.0.203.in-addr.arpa | mail.example.com. | Ask support, see below |
apt update
apt install -y ufw
ufw allow 22/tcp
ufw allow proto tcp from any to any port 25,80,587,993
ufw enable
ufw status verbosePostfix and Dovecot both need a certificate for mail.example.com. Certbot's standalone mode binds port 80 to prove you control the name, so nothing else may listen on port 80 at that moment. If a web server already runs on the VPS, use Certbot's webroot plugin instead (certbot certonly --webroot -w /var/www/html -d mail.example.com, with your own web root).
The files land in /etc/letsencrypt/live/mail.example.com/: fullchain.pem (certificate and chain) and privkey.pem (the private key, which must stay secret). Certbot's guide asks you to point services at these paths rather than copy the files.
Renewal is usually automatic: Certbot's guide says most installations schedule certbot renew, and systemctl list-timers shows the timer. The step people forget is the reload. Postfix and Dovecot load the certificate when they start or reload, and Certbot runs every executable file in /etc/letsencrypt/renewal-hooks/deploy/ after a successful renewal, so the script below reloads both. A certbot renew --dry-run does not run deploy hooks unless asked to, so run the script once by hand at the end of Step 4.
apt install -y certbot
certbot certonly --standalone -d mail.example.com
certbot certificatesmkdir -p /etc/letsencrypt/renewal-hooks/deploy
cat > /etc/letsencrypt/renewal-hooks/deploy/reload-mail.sh <<'EOF'
#!/bin/sh
systemctl reload postfix dovecot
EOF
chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-mail.sh
certbot renew --dry-run
systemctl list-timersInstall Postfix. When the installer asks, choose Internet Site and enter example.com as the system mail name. Then set main.cf with postconf -e, which edits the file for you. What the settings do:
myhostname, myorigin and mydestination: the server's name, the domain that local mail is sent from, and the names it accepts mail for, as in Postfix's basic configuration guide.inet_protocols = ipv4: send and receive over IPv4 only, the address your PTR and SPF cover. Remove it once IPv6 has its own PTR and SPF entry. Postfix must be stopped and started after this change, not just reloaded.home_mailbox = Maildir/: deliver into ~/Maildir/, where Dovecot will look.smtpd_tls_chain_files: the private key, then the certificate chain. Postfix's TLS guide prefers this setting from Postfix 3.4 on (every system here has 3.6 or later). When it is set, the old smtpd_tls_cert_file and smtpd_tls_key_file are ignored with a warning, so the second line empties them.smtpd_tls_auth_only = yes: no password is accepted over an unencrypted connection.smtpd_sasl_type = dovecot and smtpd_sasl_path = private/auth: Postfix asks Dovecot to check passwords through a socket. The path is relative to the Postfix queue directory, so it works whether or not Postfix runs chrooted, as it does by default on Debian and Ubuntu.smtpd_relay_restrictions: logged-in users may send anywhere; everybody else may only deliver to your own domains. This line is what keeps the server from becoming an open relay.The second block adds the submission service on port 587 to master.cf: TLS required (encrypt), login required, everyone else refused. To stop a logged-in user from sending under somebody else's address, Postfix's SASL guide adds smtpd_sender_login_maps with reject_sender_login_mismatch; worth doing once you have more than one user.
Then test for an open relay from another machine, not from the VPS, since mail from the server itself is trusted. Connect to port 25, give a sender and a recipient that are both outside your domains, and expect the RCPT TO line to be refused with code 554, the default answer of Postfix's reject_unauth_destination rule. The -quiet option keeps openssl from treating a line that starts with R as a command.
apt install postfix
postconf -e "myhostname = mail.example.com"
postconf -e 'myorigin = $mydomain'
postconf -e 'mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain'
postconf -e "inet_interfaces = all"
postconf -e "inet_protocols = ipv4"
postconf -e "home_mailbox = Maildir/"
postconf -e "smtpd_tls_chain_files = /etc/letsencrypt/live/mail.example.com/privkey.pem, /etc/letsencrypt/live/mail.example.com/fullchain.pem"
postconf -e "smtpd_tls_cert_file =" "smtpd_tls_key_file ="
postconf -e "smtpd_tls_security_level = may"
postconf -e "smtp_tls_security_level = may"
postconf -e "smtpd_tls_auth_only = yes"
postconf -e "smtpd_sasl_type = dovecot"
postconf -e "smtpd_sasl_path = private/auth"
postconf -e "smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination"postconf -M submission/inet="submission inet n - y - - smtpd"
postconf -P "submission/inet/syslog_name=postfix/submission"
postconf -P "submission/inet/smtpd_tls_security_level=encrypt"
postconf -P "submission/inet/smtpd_sasl_auth_enable=yes"
postconf -P "submission/inet/smtpd_client_restrictions=permit_sasl_authenticated,reject"
postconf -P "submission/inet/smtpd_relay_restrictions=permit_sasl_authenticated,reject"
postconf -Mf submission/inet
systemctl stop postfix
systemctl start postfix
postconf -nopenssl s_client -starttls smtp -connect mail.example.com:25 -crlf -quiet
EHLO test.example.net
MAIL FROM:<[email protected]>
RCPT TO:<[email protected]>
QUITInstall the IMAP server, then write your settings into /etc/dovecot/local.conf. On Debian and Ubuntu the packaged dovecot.conf reads the files in conf.d/ first and local.conf last, so your values override the defaults without touching the packaged files.
Pick the block for your version from the table above. Both do the same five things: store mail in ~/Maildir (the folder Postfix writes to), require TLS, use the Let's Encrypt files, offer the PLAIN and LOGIN mechanisms (Dovecot's howto notes that Outlook and Windows Mail work only with LOGIN), and create the socket /var/spool/postfix/private/auth that Postfix uses to check passwords, owned by the postfix user with mode 0660.
Two lines need a word on 2.4. Debian 13's 10-mail.conf keeps the inbox in /var/mail/, mbox style; mail_inbox_path = . moves it to the root of ~/Maildir, because Dovecot's settings reference makes that path relative to mail_path. And since Debian 13's dovecot.conf already opens with dovecot_config_version = 2.4.0, your local.conf must not repeat it. The protocols block turns IMAP on explicitly, as the 2.4 quick configuration does.
Run doveconf -n before you restart. It prints the settings that differ from the defaults and reports any line it cannot parse; a 2.3 name left in a 2.4 file is the usual culprit. Then restart Dovecot, run the certificate hook from Step 2 once, and check that the socket exists.
apt install -y dovecot-core dovecot-imapdmail_location = maildir:~/Maildir
ssl = required
ssl_cert = </etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.example.com/privkey.pem
auth_mechanisms = plain login
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}protocols {
imap = yes
}
mail_driver = maildir
mail_path = ~/Maildir
mail_inbox_path = .
ssl = required
ssl_server_cert_file = /etc/letsencrypt/live/mail.example.com/fullchain.pem
ssl_server_key_file = /etc/letsencrypt/live/mail.example.com/privkey.pem
auth_mechanisms = plain login
service auth {
unix_listener /var/spool/postfix/private/auth {
mode = 0660
user = postfix
group = postfix
}
}doveconf -n
systemctl restart dovecot
/etc/letsencrypt/renewal-hooks/deploy/reload-mail.sh
ls -l /var/spool/postfix/private/authWith system users, each mailbox is a Linux account: the login name is the IMAP user name, and the Linux password is the mail password. adduser asks for it; use a long, unique one, since anyone on the internet can try it against ports 587 and 993. The user alice logs in as alice and sends as [email protected].
Point root and dmarc at a real user in /etc/aliases, so that system mail and the DMARC reports of Step 6 reach someone, then rebuild the alias table with newaliases, as Postfix's aliases manual says to do after each change.
For more than a handful of mailboxes, or addresses on several domains, move to virtual users later: a passwd-file or a database in Dovecot, and virtual mailbox domains in Postfix. Dovecot's quick configuration shows the passwd-file route.
adduser alice
echo "root: alice" >> /etc/aliases
echo "dmarc: alice" >> /etc/aliases
newaliases| Setting | Incoming mail (IMAP) | Outgoing mail (SMTP) |
|---|---|---|
| Server | mail.example.com | mail.example.com |
| Port | 993 | 587 |
| Security | SSL/TLS | STARTTLS |
| User name and password | alice, her Linux password | The same |
These three records tell receivers that mail from example.com really comes from your server. SPF lists the hosts allowed to send: v=spf1 mx -all means the hosts in your MX record and nobody else, and under RFC 7208 the -all turns every other sender into a fail. DKIM signs each outgoing message with a key whose public half sits in DNS. DMARC tells receivers what to do when the checks fail and where to send reports; RFC 9989, published in May 2026, is its standard now and keeps the v=DMARC1 records you already know.
DKIM with OpenDKIM. Debian and Ubuntu keep keys in /etc/dkimkeys, a directory the package creates with the right permissions; the key file must belong to the opendkim user with mode 0600. opendkim-genkey writes mail.private (the private key) and mail.txt (the DNS record) for the selector mail; Debian's default size is already 2048 bits, and -b 2048 makes it explicit. Publish the content of mail.txt as a TXT record named mail._domainkey.example.com, joining its quoted strings if your DNS host wants one value.
Debian's /etc/opendkim.conf listens on a Unix socket under /run/opendkim/, which a chrooted Postfix cannot reach, as the file's own comments point out. Replace that Socket line with the TCP socket on port 8891 (also listed in the comments), add the domain, selector and key, then route Postfix mail through the milter. With milter_default_action = accept, mail leaves unsigned if OpenDKIM is down; Postfix 3.11 changed the default to shutdown and earlier versions use tempfail, the choice if you would rather queue mail than send it unsigned. opendkim-testkey then checks the published key against the private one.
DMARC. Start with p=none and an rua address that exists (the dmarc alias from Step 5). Read the aggregate reports for a week or two. When they show only your own server passing, move to p=quarantine, and later to p=reject.
apt install -y opendkim opendkim-tools
opendkim-genkey -b 2048 -d example.com -D /etc/dkimkeys -s mail
chown opendkim:opendkim /etc/dkimkeys/mail.private
chmod 600 /etc/dkimkeys/mail.private
cat /etc/dkimkeys/mail.txtDomain example.com
Selector mail
KeyFile /etc/dkimkeys/mail.private
Socket inet:8891@localhostpostconf -e "milter_default_action = accept"
postconf -e "smtpd_milters = inet:localhost:8891"
postconf -e 'non_smtpd_milters = $smtpd_milters'
systemctl restart opendkim postfix
opendkim-testkey -d example.com -s mail -vvv| Record | Name | Example value | What it answers |
|---|---|---|---|
| A | mail.example.com | 203.0.113.10 | Valid forward DNS for the sending host |
| PTR | 10.113.0.203.in-addr.arpa | mail.example.com. | Valid reverse DNS for the sending IP, required for every sender to Gmail |
| TXT (SPF) | example.com | v=spf1 mx -all | SPF or DKIM is required for every sender; at most 10 DNS-lookup terms |
| TXT (DKIM) | mail._domainkey.example.com | v=DKIM1; h=sha256; k=rsa; p=… (from mail.txt) | Key of 1,024 bits or more for Gmail; 2,048 recommended |
| TXT (DMARC) | _dmarc.example.com | v=DMARC1; p=none; rua=mailto:[email protected] | Required above 5,000 messages a day; p=none is accepted |
How do you test a mail server? Run these checks in order; each one catches a different fault.
dig commands below must return your MX host, the SPF, DKIM and DMARC records and, for -x, your mail hostname. An empty answer to -x means the PTR from Step 1 is not in place yet.openssl s_client must show your Let's Encrypt certificate on 25 and 587 (with STARTTLS) and on 993.Authentication-Results: you want spf=pass, dkim=pass and dmarc=pass.Then start slowly. Send real mail to a few people for some days before you move your main address: a new address that suddenly sends hundreds of messages looks like a spam source.
dig +short MX example.com
dig +short TXT example.com
dig +short TXT mail._domainkey.example.com
dig +short TXT _dmarc.example.com
dig +short -x 203.0.113.10openssl s_client -starttls smtp -connect mail.example.com:25 -servername mail.example.com
openssl s_client -starttls smtp -connect mail.example.com:587 -servername mail.example.com
openssl s_client -connect mail.example.com:993 -servername mail.example.comjournalctl -u 'postfix*' --since today
journalctl -u dovecot --since today
journalctl -u opendkim --since todayA mail server is never finished. Four routines keep it healthy:
unattended-upgrades and answer yes when dpkg-reconfigure asks; Debian's wiki says its default configuration installs security updates, not new features.certbot certificates now and then for the expiry date.postqueue -p lists mail waiting for delivery, postqueue -f retries it, and postsuper -d deletes one message by its queue ID. A queue that keeps growing means remote servers are deferring you: the log says why.Next steps sit outside this guide. fail2ban can block addresses that keep failing logins on Postfix and Dovecot, and a spam filter such as Rspamd sorts incoming junk. Keep SSH on keys only, or reachable only through a WireGuard VPN you run yourself.
Open port 25 comes with one rule on Nymhost: spam and bulk email are forbidden, and a VPS used for either is suspended. Mail for yourself, your family or your team is what this setup is for.
apt install -y unattended-upgrades
dpkg-reconfigure unattended-upgrades
postqueue -p
postqueue -f
postsuper -d QUEUE_ID
certbot certificatesNo Nymhost plan includes backups. A reinstall erases the disk, and a VPS whose renewal is not paid stops when its time runs out, with its disk kept for 7 days before it is wiped. Your mail exists only where you copy it.
What to save:
~/Maildir;/etc/postfix, /etc/dovecot and /etc/aliases;/etc/opendkim.conf and /etc/dkimkeys (lose the key and you must publish a new DKIM record);/etc/letsencrypt, or simply request a new certificate after a rebuild.Where: on another machine, such as a second server or your own computer. Never only on the same VPS.
How. A plain rsync of a live Maildir can copy a message twice or miss one that moves during the copy. doveadm backup makes a one-way copy through Dovecot instead: its manual says the destination ends up exactly like the source. The destination is written like a mail location (maildir: and a path, ~ being the user's home). Run it for each user, archive the configuration, then pull both to your backup machine with rsync over SSH. --delete removes from the copy what is gone from the server, so keep several generations (one folder per weekday, for instance) in case a mistake is copied over your only backup.
Schedule the server-side commands with cron or a systemd timer, at night. Test a restore at least once: copy a backup into a new test user's ~/Maildir, give the files to that user, and open the mailbox in a mail client. A backup you have never restored is a guess.
doveadm backup -u alice maildir:~/Maildir-backup
tar -czf /root/mail-config.tar.gz /etc/postfix /etc/dovecot /etc/aliases /etc/opendkim.conf /etc/dkimkeys /etc/letsencrypt
# crontab -e, then for example:
# 30 3 * * * doveadm backup -u alice maildir:~/Maildir-backuprsync -a --delete -e ssh [email protected]:/home/alice/Maildir-backup/ ./alice-Maildir/
rsync -a -e ssh [email protected]:/root/mail-config.tar.gz ./# on the VPS
adduser restoretest
# on the backup machine
rsync -a -e ssh ./alice-Maildir/ [email protected]:/home/restoretest/Maildir/
# on the VPS again
chown -R restoretest:restoretest /home/restoretest/MaildirMost faults show up in the journal within seconds of a test. Start from the symptom, check the likely cause, and change one thing at a time. If the IP address itself is the problem, no setting fixes it: check IP reputation before you buy a plan or move your mail.
| Symptom | Likely cause | Check with |
|---|---|---|
| Port 25 times out from outside | Firewall rule missing, or Postfix listening on localhost only | ufw status verbose, postconf inet_interfaces |
| Remote server refuses mail and mentions reverse DNS | No PTR for the IP, or one that does not match mail.example.com | dig +short -x 203.0.113.10, then ask support |
| Mail client warns of an expired certificate | Renewal failed, or the services were not reloaded | certbot certificates, then run the deploy hook |
| Dovecot will not start after a move to Debian 13 | 2.3 setting names in a 2.4 configuration | doveconf -n, journalctl -u dovecot |
| Login fails in the mail client | Wrong port or security type, or a cleartext login refused | 993 with SSL/TLS, 587 with STARTTLS; journalctl -u dovecot |
| Messages land in spam | DKIM missing or failing, IP on a blocklist, or a new address with no history | Authentication-Results header, opendkim-testkey, a blocklist lookup |
| Mail waits in the queue | Remote servers defer you (rate limits or reputation) | postqueue -p and the log line for that message |
Not in practice. Your MX record, your SPF record and the PTR all point at one address, and receivers judge your mail by its history. Every Nymhost VPS comes with one dedicated IPv4 address, which is what a mail server needs.
Yes. Outbound port 25 is open on every Nymhost VPS, so Postfix can deliver straight to other servers without a relay. Sending spam or bulk email is forbidden and gets the VPS suspended.
It depends on the system. Debian 13 installs Dovecot 2.4.1; Debian 12 (2.3.19.1), Ubuntu 24.04 (2.3.21) and Ubuntu 22.04 (2.3.16) install 2.3. Postfix works the same with both. Use the matching Dovecot file from Step 4, because 2.4 refuses several 2.3 setting names.
The server itself is the main cost. Offshore 2 (2 GB RAM) costs $4.89 for one month, or $3.42 a month when paid for 12 months; Global 2, also 2 GB, costs $3.19. Compare the options on the VPS for email server page. The domain is a separate cost at your registrar.
No. Desktop and phone mail clients connect over IMAP on port 993 and SMTP on port 587, and that is all this setup needs. Roundcube adds a web server, PHP and a database to the VPS; add it only if you want to read mail in a browser. The Roundcube webmail guide continues from this setup.
Copy each Maildir with doveadm backup, archive /etc/postfix, /etc/dovecot, the DKIM key and the certificates, then pull everything to another machine with rsync over SSH every night. Keep several generations and test a restore. No Nymhost plan includes backups.
Yes. A mail server without KYC is possible on Nymhost: the VPS needs no ID, no phone number and no card, and you pay in crypto. Your domain registrar and DNS host have their own rules, and public records such as MX and SPF are visible to everyone.
Offshore 2 or Global 2 (2 GB) for a few mailboxes; Offshore 4 or Global 4 (4 GB) once you add a spam filter. Compare memory needs on which VPS for a mail server, or see every Nymhost VPS plan and the anonymous Linux VPS offer.
Amsterdam · Reykjavik · Zurich · Bucharest
$3.09/ month
3 mo $8.346 mo $14.8312 mo $25.95
$4.89/ month
3 mo $13.206 mo $23.4712 mo $41.07
$8.19/ month
3 mo $22.116 mo $39.3112 mo $68.79
$13.49/ month
3 mo $36.426 mo $64.7512 mo $113.31
$20.49/ month
3 mo $55.326 mo $98.3512 mo $172.11
New York · Dallas · Los Angeles · London · Amsterdam · Frankfurt
$3.19/ month
3 mo $8.616 mo $15.3112 mo $26.79
$6.39/ month
3 mo $17.256 mo $30.6712 mo $53.67
$9.59/ month
3 mo $25.896 mo $46.0312 mo $80.55
$19.19/ month
3 mo $51.816 mo $92.1112 mo $161.19
$29.39/ month
3 mo $79.356 mo $141.0712 mo $246.87
Prices in US dollars, checked on 18 November 2026. Paid from a crypto balance (minimum top-up $25); 3, 6 and 12 months save 10, 20 and 30%. Every plan: KVM, root over SSH, 1 dedicated IPv4 + /64 IPv6, shared 1 Gbit/s port.
Outbound port 25 is open on every plan, paid in crypto without KYC, built by a person usually within minutes.