Mail server on a VPS: SPF, DKIM, DMARC
Installing Postfix or a ready-made bundle like Mailcow on a VPS takes an hour. Getting your mail into the inbox rather than spam is harder: mailbox providers look at the port, the server's address, its reputation and three DNS records. Here is what to check with the host before buying and how to set up SPF, DKIM and DMARC.
A mail server does two different jobs: it receives mail for your domain and sends your mail to other servers. Receiving almost always works right away if DNS has an MX record. Sending is harder: the receiving side decides whether to trust your server and checks the network, the address and the signatures to do so. If even one link is not set up, messages are rejected or land in spam without any notice.
Port 25 at hosting providers
Servers pass mail to each other over port 25. Ports 587 and 465 are for programs that hand a message to their own server; a message reaches someone else's MX server only via port 25. So the main condition for your own mail is an open outbound port 25.
Many hosts close it by default: new servers are often used to try sending spam, and the complaints and bad reputation fall on the host's addresses. According to the accsly catalog as of 3 November 2026, the port 25 terms could be established for 117 hosts: for 39% it is closed, for 37% it is opened on request, and for 24% it is open from the start. Large cloud platforms often close it for good, with no way to open it.
If the port is opened on request, the host usually wants to know the domain, what the mail is for, and sometimes that the server has been paid for more than a day. Say it plainly: "corporate mail for the domain, about N messages a day, no bulk mailings". To check the port on a server you already have: nc -vz -w 5 gmail-smtp-in.l.google.com 25 — if there is no connection, the port is closed on the host's side. Plans from hosts where the port is open or opened on request are in VPS for a mail server.
PTR and the server name
Google requires every sender's server address to have a reverse DNS record (PTR) that matches the forward one. The scheme: the server has a name, for example mail.example.com; that name's A record points to the server's address, the address's PTR points back to mail.example.com, and the server introduces itself with the same name in the HELO command. The PTR is set by the host, in the panel or through support. If mail also goes out over IPv6, the IPv6 address needs a PTR too. Details are in IPv4 and IPv6 on a server. On a NAT VPS without its own address you cannot set your own PTR, and such a server is not suitable for mail.
IP address reputation
A VPS address could have belonged to anyone before you. If spam was sent from it, it may be on public lists of known spam sources (DNSBL), and some mailbox providers will reject your mail from day one. Before launch, check the address in public reputation lookup services; if it is listed, ask the host for another one or file a removal request — most lists have such a form.
A new clean address has a different problem: it has no history, and the big providers treat it with caution. Start with a small volume of mail to real recipients and increase it gradually. Google requires keeping the share of messages that recipients mark as spam below 0.3%; you can watch it in the free Google Postmaster Tools. Bulk mailings are better sent through a separate service, or at least from a separate address and subdomain, so that their reputation does not affect your working mail.
SPF: who may send on behalf of the domain
SPF (RFC 7208) is a TXT record at the domain root listing the servers allowed to send mail on its behalf. The receiving server checks it against the envelope sender address (MAIL FROM) and the HELO name.
example.com. TXT "v=spf1 mx ip4:203.0.113.10 -all"
mxandip4:are your servers; if mail also goes out through an external service, add itsinclude:.-allmeans everyone else is not allowed to send (fail),~allmeans "probably not" (softfail), handy while you are setting things up.- A domain must have exactly one SPF record. Mechanisms that need DNS lookups (
include,a,mx,exists,redirect) may be used no more than 10 times including nested ones; beyond that the check returns an error (permerror) and SPF does not work at all.
DKIM: signing messages
DKIM (RFC 6376) is a digital signature over a message's headers and body. The server signs every message with a private key, and the public key is published in DNS under selector._domainkey.example.com. The recipient verifies the signature and confirms that the message was sent by the domain in the signature and was not altered on the way.
mail2026._domainkey.example.com. TXT "v=DKIM1; k=rsa; p=MIIBIjANBgkq..."
The RSA key length must be at least 1024 bits, as RFC 8301 and Gmail require; 2048 is recommended. Keys are generated by OpenDKIM, rspamd or the panel of a mail bundle, which will also give you the ready record. The selector is there for key rotation: publish the new key under a new selector, switch signing over, and delete the old record a few days later, once the messages already sent have been checked.
DMARC: policy and reports
DMARC (RFC 7489) ties SPF and DKIM to the From address the recipient sees. A message passes DMARC if SPF or DKIM passed and its domain matches the domain in From (by default a match of the organisational domain is enough). The record is published under the name _dmarc:
_dmarc.example.com. TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com"
p=nonemeans monitor only,p=quarantinesends messages that fail DMARC to spam,p=rejectrejects them.ruais the address for daily aggregate reports: they show who sends mail on behalf of the domain and from which addresses.
Start with p=none, read the reports for 2–4 weeks, make sure all your legitimate mail sources pass, then move to quarantine and then to reject.
What Gmail and Outlook require
Since 1 February 2024 Gmail has required every sender to have SPF or DKIM, a correct PTR record, delivery over TLS and a spam complaint rate below 0.3%. Those who send more than 5,000 messages a day to Gmail addresses need SPF and DKIM together, a DMARC record (p=none is enough) with the From domain matching the SPF or DKIM domain, and one-click unsubscribe in marketing mail. Since 5 May 2025 Outlook.com has applied similar rules to senders of 5,000+ messages a day: SPF and DKIM must pass, DMARC must be at least p=none with a domain match; messages without this go to the Junk folder or are rejected.
For a small server the conclusion is simple: set up all three records at once, even if you send little. To check the result, send a message to your own Gmail mailbox and open "Show original": it shows the SPF, DKIM and DMARC results.
When you do not need your own mail server
Your own server makes sense if you need control over mailboxes and data, or many addresses on several domains. If the site only needs to send notifications and port 25 is closed, it is simpler to send through an external mail service on port 587: SPF, DKIM and DMARC are still set up for your domain. A server with full mail and spam filtering needs 2 GB of memory; plan disk space with room for mailboxes and backups. When a site and its mail should move from shared hosting to a VPS is covered in When to move from shared hosting to a VPS.