How to Set Up Email Sending from Your VPS Without Landing in Spam

How to Set Up Email Sending from Your VPS Without Landing in Spam

Running email sending from your vps sounds simple: install Postfix, point your app at localhost, and start sending. In practice, much of that mail never reaches the inbox. Gmail, Outlook, and Yahoo filter hard against unknown senders, and a fresh VPS IP has no track record at all. This guide walks through the full setup: the three DNS records that prove you own your domain, the reverse DNS entry your host must set, why port 25 is blocked on many VPS plans, and how to use an SMTP relay when direct sending is not an option. You will also learn how to test each message before real users see it.

Why Email Sending From Your VPS Often Lands in Spam

Receiving servers decide in milliseconds whether your message looks safe. They check three things: does the sending IP match the domain in the From header, does the domain publish authentication records, and does the IP have a sending history. A new VPS fails all three by default. It has no history, no authentication records, and often sits in an IP range that other customers used to send spam from before.

That last point catches many people off guard. You can configure everything right and still land in spam for the first weeks while your IP builds a record. Sending a small volume of wanted mail, keeping bounce rates low, and fixing authentication first is the only way through it. If you are still working through a fresh server, our checklist of the first things to do after buying a VPS covers the security basics to finish before you send anything.

Why Port 25 Is Blocked on Most VPS Plans

Port 25 is the port servers use to talk to each other. It is also the port spammers abuse, so many VPS providers block outbound port 25 by default on new accounts. Some open it after a support ticket and a waiting period. Others never open it on cheap plans. Before you spend an hour configuring Postfix, test whether the port is even open:

nc -vz -w 5 gmail-smtp-in.l.google.com 25

If the connection times out, your provider blocks it. Check your provider docs or open a ticket to ask. Do not assume a failed test means your mail server is broken. On some hosts the block lifts after you verify your account or after a few weeks of clean use. If the port stays closed, skip direct sending entirely and use a relay, covered below.

Port 587 is different. That is the submission port your apps and mail clients use to hand mail to a relay with a login. Providers rarely block 587, which is why a relay works even when port 25 does not.

Publish SPF, DKIM, and DMARC Records

These three DNS records are the core of any spf dkim dmarc setup. Each one answers a different question for the receiving server.

SPF lists which servers may send mail for your domain. A basic record for a server that sends directly looks like this:

v=spf1 ip4:203.0.113.10 -all

Replace the IP with your VPS address. The -all at the end tells receivers to reject mail from any server not listed. If you send through a relay, add the relay’s include instead, for example include:spf.sendgrid.net. Keep the record to one TXT entry per domain; two SPF records break validation.

DKIM adds a digital signature to each message so receivers can confirm it was not changed in transit. Install OpenDKIM, generate a key pair, and publish the public key as a TXT record:

sudo apt install opendkim opendkim-tools
opendkim-genkey -b 2048 -d example.com -D /etc/opendkim/keys/ -s mail -v

The command writes a TXT record you paste into DNS. Then point Postfix at the OpenDKIM socket so every outgoing message gets signed. If the signature check fails, receivers treat the message as unsigned, which is no worse than having no DKIM at all, but it is also no help.

DMARC tells receivers what to do when SPF or DKIM fails, and where to send reports. Start with a monitoring policy so you can see failures before you enforce anything:

v=DMARC1; p=none; rua=mailto:[email protected]; pct=100

After a week of clean reports, move to p=quarantine, then p=reject. Jumping straight to reject with a misconfigured SPF record can block your own legitimate mail.

All three records live in DNS, so a DNS panel you already use works fine. If your DNS runs through Cloudflare, our guide to setting up Cloudflare in front of your VPS shows where those records go.

Set a PTR Record for Reverse DNS

Reverse DNS maps your IP back to a hostname. Many receivers check it and reject mail when the PTR record is missing or does not match the name your server announces in its greeting. A proper vps reverse dns setup means the PTR record for your IP points at your mail hostname, such as mail.example.com, and that hostname resolves forward to the same IP.

You cannot set this record in your domain DNS panel. PTR records belong to whoever owns the IP range, which is your VPS provider. Most providers let you set it from the control panel next to the server IP settings. Some require a support ticket. Either way, set the PTR to your mail hostname, then check it with:

dig -x 203.0.113.10 +short

If the answer is empty or points at a generic name like vps-203-0-113-10.provider.net, the record is not set. Our walkthrough of reverse DNS and PTR records on a VPS covers the provider panels in more detail.

Send Through an SMTP Relay

A vps smtp relay takes your outgoing mail and delivers it from its own servers. You trade a small fee for a warm IP, managed authentication, and delivery reporting. For most small sites this beats direct sending, because one shared IP with a good record delivers better than a fresh VPS IP with none.

Relay pricing varies by provider and volume, usually a few dollars a month for low volume, so check official pricing before you commit. The setup is the same shape for most relays. In Postfix, set the relay host and credentials:

# /etc/postfix/main.cf
relayhost = [smtp.sendgrid.net]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_security_level = encrypt

Then store the login in /etc/postfix/sasl_passwd, run postmap on it, and reload Postfix. Test with a message to an address you control and read the headers to confirm the relay handled delivery. Keep the relay as your only outbound path; sending some mail direct and some through the relay splits your reputation across two IPs and makes problems harder to trace.

Test Every Change With Mail-Tester

Guessing whether your setup works wastes days. Send a test message to the address mail-tester.com gives you, then open the report link. The tool scores your message out of 10 and lists each failure: missing SPF, bad DKIM signature, no reverse DNS, broken HTML, or a URL on a blocklist. Your mail-tester score should sit at 9 or above before you send real mail. Fix the red items first, then the orange ones.

Re-test after every change: a new relay, a DNS edit, a Postfix update. DNS changes can take minutes to hours to spread, so if a record you just added shows as missing, wait and test again before you change anything else.

Keep Your Sender Reputation Clean

Authentication gets you through the door. Reputation decides whether you stay in the inbox. Send only to people who asked for your mail, remove addresses that bounce, and never buy a list. A sudden jump from ten messages a day to ten thousand looks like a spam run to every filter, so raise volume slowly on a new IP. If your mail starts landing in spam after months of clean delivery, check whether your IP landed on a blocklist and look for a compromised script sending mail without your knowledge. Our guide on finding the source when your VPS is sending spam walks through exactly that check.

Start with the DNS records, add the PTR entry, pick direct sending or a relay, and test before you send anything real. That order fixes most delivery problems before they start.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.