SELF-HOSTED EMAIL SERVER

The honest three-tier decision, plus a send-only Postfix relay with correct SPF, DKIM and DMARC so your server's mail actually lands.

Outbound email from your own dedicated server

 

Self-hosted email server: outbound mail from a dedicated server, done honestly

Most people who ask whether they should run a self-hosted email server are asking the wrong question. Full mailboxes with IMAP are a months-long reputation project, and for most teams a hosted mailbox provider is the better call. But every dedicated server needs one thing that is easy and worth doing well: correct outbound mail, so its cron jobs, monitoring alerts and app notifications actually arrive instead of vanishing into spam folders. This guide sorts the honest decision into three tiers and then walks the setup that almost everyone actually needs.

The reader here is the sysadmin. Server.Biz sells unmanaged dedicated servers, so the box, the DNS and the mail queue are yours to run. Everything below is standard, well-documented practice on Ubuntu 24.04 LTS, with every command ready to paste and every DNS record ready to copy.

Should you self-host email? Three honest tiers

The phrase "self-host email" hides three very different jobs, and confusing them is how people end up with a broken, blocklisted mail server they never needed. Sort your actual need into one of three tiers before you install anything.

Tier 1 is a send-only relay. Your server generates mail: a failed backup cron job wants to email you, your monitoring stack sends an alert, your web app sends a password reset. All of that needs to leave the machine and land in a real inbox. This is the tier every server needs, and it takes about an hour.

Tier 2 is application mail at volume. Your product sends transactional email, receipts, sign-up confirmations, notifications, through your own Postfix with proper DNS behind it. This is a real but achievable step: correct SPF, DKIM and DMARC, a matching reverse DNS record, and a slow warm-up of your sending IP. Many teams run this happily.

Tier 3 is full mailboxes: real inboxes with IMAP that people log into, send from, and store years of mail in. Be blunt with yourself here. Deliverability from a fresh IP address is a reputation project measured in months, not an afternoon, and the operational load (spam filtering, blocklist monitoring, backups, storage) never ends. For most teams a hosted mailbox provider is the honest better choice. Tier 3 wins only in specific cases, covered later.

What it is Who needs it Effort
Tier 1: send-only A relay for cron, alerts and app notifications Every server About an hour
Tier 2: app mail Your apps send real volume through your Postfix and DNS Many teams A day, plus DNS and warm-up
Tier 3: full mailboxes IMAP inboxes people log into and store mail in Few, with strong reasons An ongoing project

Deliverability physics: how receivers judge your mail

Before any config, understand what a receiving mail server checks when your message arrives. It cannot see your intentions, so it judges you on a handful of signals. Get these right and your mail lands; get them wrong and even a single honest alert goes to spam or is rejected outright. There are six that matter.

PTR, or reverse DNS, maps your server's IP address back to a hostname. Almost every large receiver rejects mail from an IP with no PTR record or a generic one. This is the one record you do not set in your own DNS: it is configured through your server provider for the IP they assigned you. Ask the provider to set the PTR for your IP to your mail hostname (for example mail.YOUR_DOMAIN); the exact way you request it varies by provider, so do not expect a specific control-panel button.

SPF (Sender Policy Framework) is a DNS record listing which IP addresses are allowed to send mail for your domain. A receiver looks up your SPF record and checks whether the connecting server is on the list. If your server is not listed, the message looks forged.

DKIM (DomainKeys Identified Mail) signs each outgoing message with a private key held on your server. The matching public key lives in your DNS. The receiver verifies the signature, which proves the message really came from your domain and was not altered in transit.

DMARC (Domain-based Message Authentication) ties SPF and DKIM together and tells receivers what to do when a message fails both: nothing, quarantine it, or reject it. It also asks receivers to send you reports, so you can see who is sending mail as your domain.

IP reputation is the receiver's memory of how your IP has behaved. A fresh IP has no reputation, which is neutral at best and treated with suspicion at worst. Reputation is built slowly by sending wanted mail that people open and do not mark as spam, and it is destroyed quickly by sending to bad addresses or triggering complaints.

Volume consistency is the last signal. Sending ten messages a day for a month, then suddenly ten thousand, looks exactly like a compromised server. Receivers reward steady, predictable patterns. This is why a fresh IP has to be warmed up gradually rather than opened at full volume.

Tier 1: a send-only Postfix relay

Here is the setup nearly every server needs. Postfix runs locally, accepts mail only from the machine itself, and delivers it out to the internet. It never listens on the public network, so it can never be an open relay for spammers. This is the safe default and takes minutes on Ubuntu 24.04.

Install Postfix non-interactively by pre-seeding the two debconf answers, choosing the "Internet Site" role and setting the mail name to your domain. Substitute YOUR_DOMAIN throughout with your real domain.

Pre-seed the answers, then install Postfix and the mailutils package that gives you the mail command for testing.

shell
echo "postfix postfix/mailname string YOUR_DOMAIN" | sudo debconf-set-selections
echo "postfix postfix/main_mailer_type string 'Internet Site'" | sudo debconf-set-selections
sudo apt update
sudo apt install -y postfix mailutils

Set the minimal send-only configuration. inet_interfaces = loopback-only is the line that matters most: it binds Postfix to 127.0.0.1 so nothing on the public internet can ever connect to it. Set myhostname to your mail hostname, the same name you asked your provider to use for the PTR record.

shell
sudo postconf -e "inet_interfaces = loopback-only"
sudo postconf -e "inet_protocols = all"
sudo postconf -e "myhostname = mail.YOUR_DOMAIN"
sudo postconf -e "mydestination = localhost"
sudo systemctl restart postfix

Send a test message to an inbox you can check. Replace you@example.net with a real address at a provider you control.

shell
echo "This is a test from my dedicated server." | mail -s "Server test" you@example.net

If that message arrives, direct sending works and Tier 1 is done, once you add the DNS records in the next section. If it lands in spam or does not arrive at all, that is expected without SPF, DKIM and DMARC in place. Do not skip them: a fresh dedicated-server IP with no authentication records is treated as suspect by every major receiver.

When to relay through an external SMTP service instead

Sometimes direct sending is not worth it. If your server's IP is new, or shares a range with a poor reputation, or you simply cannot invest weeks in building trust, relay your mail through an external SMTP service that already has good reputation. Your Postfix hands every message to their servers, which do the actual delivery. This trades control for reliability, and it is the pragmatic choice for a low-volume server whose mail simply has to arrive.

Be honest about what this is: you are outsourcing your sending reputation to someone else. That is a reasonable trade for alerts and notifications, and a poor one if your goal was independence. Configure Postfix to authenticate to the relay and forward everything to it.

Point Postfix at the relay and turn on authenticated, encrypted submission. Replace smtp.relay-provider.com with your provider's submission host; port 587 is the standard.

shell
sudo postconf -e "relayhost = [smtp.relay-provider.com]:587"
sudo postconf -e "smtp_sasl_auth_enable = yes"
sudo postconf -e "smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd"
sudo postconf -e "smtp_sasl_security_options = noanonymous"
sudo postconf -e "smtp_tls_security_level = encrypt"

Store the credentials your relay gave you. Create /etc/postfix/sasl_passwd with one line: the relay host and port, then your username and password.

/etc/postfix/sasl_passwd
[smtp.relay-provider.com]:587 YOUR_RELAY_USERNAME:YOUR_RELAY_PASSWORD

Compile the file into the hashed map Postfix reads, lock down its permissions so the credentials are root-only, and reload.

shell
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
sudo systemctl reload postfix

With a relay in place, the receiver sees the relay's IP and reputation, not yours, so the SPF and DKIM records that matter are usually the relay's (they will document exactly what to publish). You still want a DMARC record on your own domain. If you later build your own reputation, remove the relayhost line and switch back to direct sending.

SPF, DKIM and DMARC: the DNS that makes mail land

For direct sending, these three DNS records are what turn your server from an anonymous IP into a trusted sender. Add them at your DNS host as TXT records. The examples use YOUR_DOMAIN for your domain and 203.0.113.10 for your server's public IPv4 address; substitute both. Zone-file lines are shown; most DNS panels ask only for the name and the quoted value.

SPF: publish one TXT record on your root domain listing who may send. "a mx" authorises the hosts in your A and MX records; "ip4:" adds your sending IP explicitly. The final token is the policy: -all means "reject anything not listed" (a hard fail), while ~all means "soft fail, accept but mark suspicious". Start with ~all while testing, then tighten to -all once you have confirmed your own server passes.

DNS TXT record
YOUR_DOMAIN.   IN TXT   "v=spf1 a mx ip4:203.0.113.10 -all"

DKIM starts on the server. Install OpenDKIM and its tools, then generate a 2048-bit key with the selector "mail" for your domain.

shell
sudo apt install -y opendkim opendkim-tools
sudo mkdir -p /etc/dkimkeys
sudo opendkim-genkey -b 2048 -d YOUR_DOMAIN -s mail -D /etc/dkimkeys
sudo chown -R opendkim:opendkim /etc/dkimkeys

Configure OpenDKIM to sign with that key. Append these lines to /etc/opendkim.conf. The inet socket on port 8891 is how Postfix will reach it.

/etc/opendkim.conf
Domain                  YOUR_DOMAIN
Selector                mail
KeyFile                 /etc/dkimkeys/mail.private
Socket                  inet:8891@localhost
Canonicalization        relaxed/simple
Mode                    s

Wire OpenDKIM into Postfix as a milter, so every outgoing message is signed on its way out, then restart both services.

shell
sudo postconf -e "milter_default_action = accept"
sudo postconf -e "milter_protocol = 6"
sudo postconf -e "smtpd_milters = inet:localhost:8891"
sudo postconf -e "non_smtpd_milters = inet:localhost:8891"
sudo systemctl restart opendkim postfix

opendkim-genkey wrote the public key into /etc/dkimkeys/mail.txt, already formatted as a DNS record. Print it and publish it as a TXT record at mail._domainkey.YOUR_DOMAIN. The p= value is your public key; it is long, and it must be pasted exactly.

shell
sudo cat /etc/dkimkeys/mail.txt

The resulting record looks like this (your p= value will differ). Some DNS panels need the quoted string joined into one; others accept the split form as generated.

DNS TXT record
mail._domainkey.YOUR_DOMAIN.   IN TXT   "v=DKIM1; k=rsa; p=MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A...QAB"

DMARC: publish one TXT record at _dmarc.YOUR_DOMAIN. Start with p=none, which enforces nothing but asks receivers to send you aggregate reports at the rua address, so you can watch what is passing and failing. Point rua at a mailbox you actually read.

DNS TXT record
_dmarc.YOUR_DOMAIN.   IN TXT   "v=DMARC1; p=none; rua=mailto:dmarc@YOUR_DOMAIN; fo=1"

Run p=none for a week or two and read the reports. Once they confirm your legitimate mail passes SPF and DKIM cleanly, raise the policy to p=quarantine (failing mail goes to spam) and, when you are confident, to p=reject (failing mail is refused). Moving straight to reject before you have read a single report is how people silently block their own newsletters.

Verify it works: swaks, dig and the mail log

Do not trust a setup you have not tested. Four checks confirm the whole chain: a real test send, a look at how a receiver scored it, DNS lookups on each record, and the mail log for what Postfix actually did.

swaks is the Swiss Army knife for SMTP testing. Install it and send a message straight through your local Postfix, watching the full conversation.

shell
sudo apt install -y swaks
swaks --to you@example.net --from notify@YOUR_DOMAIN --server localhost

Check how a receiver actually scored the message. Free tools of the mail-tester type give you a temporary address; send one message to it and it grades your SPF, DKIM, DMARC, PTR and content, showing exactly what failed. Send to the address it shows you.

shell
swaks --to the-address-it-gave-you@example.com --from notify@YOUR_DOMAIN --server localhost

Verify each DNS record resolves as you published it. The last line is the reverse-DNS (PTR) check on your IP: it should return your mail hostname, not a generic provider name.

shell
dig +short TXT YOUR_DOMAIN
dig +short TXT mail._domainkey.YOUR_DOMAIN
dig +short TXT _dmarc.YOUR_DOMAIN
dig +short -x 203.0.113.10

Watch Postfix work in real time. Send a test in another terminal and read what the receiver said back: a "250" status with "sent" is success, while "reject" or a "421"/"550" tells you what to fix.

shell
sudo tail -f /var/log/mail.log

The mail log is the single most useful file when delivery fails. Receiver rejections are quoted verbatim there, often with a URL explaining the exact reason, whether that is a missing PTR, an SPF fail, or the IP being on a blocklist. Read the log before changing anything.

Tier 3: full mailboxes, and why it is a reputation project

If you genuinely need real inboxes, here is the honest shape of it. A full stack is Postfix for sending and receiving, Dovecot for IMAP so clients can read and store mail, a spam filter such as Rspamd on the inbound side, and a webmail interface if people want browser access. The packaged path most people take is docker-mailserver, which bundles a tested combination of these into one container and spares you wiring them together by hand.

The software is the easy part. The operational reality is the cost: you monitor blocklists daily and react fast when your IP lands on one, you think about a backup MX so mail is not lost when the server is down, you plan storage that only grows as inboxes fill, and you keep backups of mail that people expect to keep forever. None of this is exotic, but all of it is now your job, permanently.

Three things justify Tier 3. Data-sovereignty requirements that forbid a third party from holding your mail. An existing, warmed sending reputation you are migrating rather than starting cold. And real volume where a hosted provider's per-mailbox pricing stops making sense. If none of those is true, a hosted mailbox provider will deliver better mail with less of your time, and choosing it is not a defeat.

Staying deliverable over time

Reputation is earned continuously, not set once. Send at a consistent volume: warm a new IP up slowly over weeks rather than opening the taps on day one, and avoid sudden spikes that look like a compromise. Keep your lists clean by removing addresses that bounce, because repeatedly hitting dead mailboxes is a strong spam signal. Never buy a mailing list; it is the fastest route to a blocklist and it poisons the reputation of every legitimate message you send afterwards.

Watch the blocklists and read your DMARC reports. A handful of free services will tell you if your IP appears on a major blocklist, and finding out early is the difference between a quick delisting request and days of bounced mail. The DMARC aggregate reports arriving at your rua address are the running record of who is sending as your domain and whether it passes: skim them, and they will show you both your own misconfigurations and anyone trying to spoof you. Feed all of this into whatever alerting you already run, so a delivery problem pages you instead of being discovered by an angry customer.

Effort by tier, and where to start

The decision comes down to matching effort to need. Almost everyone stops at Tier 1, and that is the right answer.

Tier Effort When it wins
Send-only relay About an hour, once Always: every server needs its outbound mail to arrive
App mail at volume A day, plus DNS and IP warm-up Your product sends transactional mail and you want to own the pipeline
Full mailboxes Weeks to build, ongoing to run Data-sovereignty rules, migrating an existing reputation, or real volume

Where to start

Do Tier 1 today: a send-only Postfix bound to loopback, then SPF, DKIM and DMARC, verified with swaks and dig. Harden the box itself first with our getting-your-server-online guide, and point the alerts your new mail setup can now deliver at real monitoring, so a failed backup or a full disk actually reaches you. Mail that nobody receives is the same as no mail at all.

Continue reading

Need help choosing?

Our experts can help you find the perfect server for your needs.

Contact us »