Run a Mail Server on a VPS With an SMTP Relay
By Harborvm7 min read
Key takeaways
- You can run a mail server on a VPS with blocked port 25 by sending through a smarthost on port 587 with SPF, DKIM and DMARC set up.
- For receiving, point your MX record at an inbound relay that forwards to a high port, or tunnel port 25 from a small helper VPS over WireGuard.
- Harborvm blocks outbound port 25 and gives each customer a private IP behind the server, so plan your sending and receiving around that from the start.
- If you only need a few mailboxes, a hosted provider like Zoho or Google Workspace is usually less work than self-hosting.
Yes, you can run a mail server on a VPS even when the host blocks outbound port 25 and gives you no dedicated public IPv4. You send through an SMTP relay on port 587 and you receive by pointing your MX record at an inbound relay that forwards to a high port. This guide shows the exact setup on Harborvm, where both of those limits apply, and where a hosted mailbox is the easier answer.
Mail is the one service that punishes a VPS the hardest. The protocol is old, the anti-spam rules are strict, and the defaults on most hosts work against you. Read this before you install Postfix, so you build the right shape from the start.

Why you cannot run a mail server on a VPS the normal way
Port 25 is the port servers use to hand mail to each other. It is also the port spammers abuse most, because any infected machine can open a connection and start blasting. To protect the reputation of their address ranges, almost every host blocks outbound port 25 by default. The large clouds do this too: Google Cloud, AWS, Azure and DigitalOcean all restrict outbound 25 on new servers.
Harborvm blocks outbound port 25 as well. We do not unblock it on request. That keeps our address ranges clean for everyone and keeps your other services off spam blocklists.
The second limit is addressing. Harborvm does not give each VPS a dedicated public IPv4. Your VM sits on a private address behind the server's shared IP, and you expose services through forwarded ports, up to 10 per VPS. A normal mail server expects to own a public IP on port 25 in both directions. You do not have that here, so you work around it. The good news is that the workaround is also what gives you reliable delivery.
Both limits push you toward the same design: let a specialist handle the raw port 25 traffic to the internet, and keep your server talking to that specialist over authenticated, unblocked ports.
Sending: relay through a smarthost on port 587
Outbound is the easy half. You configure your mail server to forward all outgoing mail to a smarthost, an external SMTP service that owns clean IPs and talks to the world on port 25 for you. You connect to it on port 587 (submission) with a username and password. Common choices are Amazon SES, Mailgun, Brevo and SMTP2GO. Pick on price and region, then follow their setup.
On a plain Postfix box, the relay config is short. Edit /etc/postfix/main.cf:
relayhost = [smtp.your-relay.com]: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
Put your credentials in /etc/postfix/sasl_passwd:
[smtp.your-relay.com]:587 your-username:your-password
Then hash the file and reload:
sudo postmap /etc/postfix/sasl_passwd
sudo chmod 600 /etc/postfix/sasl_passwd*
sudo systemctl reload postfix
If you run a full stack like Mailcow, you set the same smarthost in its admin UI under the relay settings. The principle is identical: nothing leaves your VPS on port 25, so nothing hits the block.
Authenticate so your mail gets delivered
A relay gets your mail out, but inbox providers still decide whether to trust it. Publish three DNS records on your domain:
- SPF lists the servers allowed to send for your domain. Your relay gives you the exact value. SPF is defined in RFC 7208, an open IETF standard, so the behavior is the same everywhere.
- DKIM signs each message with a key so the receiver can confirm it was not altered. Your relay generates the key and gives you the DNS record to publish.
- DMARC ties SPF and DKIM together and tells receivers what to do when a message fails. Start with a monitoring policy, read the reports, then tighten it.
These three are not optional in practice. Full DMARC enforcement is still uncommon, one 2026 analysis found only around 9 percent of domains fully protected despite much wider adoption, per DMARCReport. Getting all three right puts you ahead of most senders and keeps your mail out of spam folders.
Receiving: get port 25 traffic to your VPS
Inbound is the harder half, because the sending server on the far side will connect to you on port 25, and you have neither an open port 25 nor a dedicated IP. You have two honest options.
Option A: an inbound relay service. Several providers accept mail for your domain on their own IPs, then forward it to any host and port you choose. You point your domain's MX record at the relay, and open one of your 10 forwarded ports on Harborvm (say, external port 2525) mapped to port 25 on the VM. The relay delivers each message to that high port. Your mail server never needs a public port 25 of its own.
Option B: a small helper VPS with a WireGuard tunnel. Rent a tiny server somewhere that does allow inbound port 25, run WireGuard between it and your Harborvm VPS, and have the helper forward port 25 traffic through the tunnel. Harborvm gives every customer a private network and built-in WireGuard, so the tunnel end on our side is quick to set up. If you have not used WireGuard before, our guide on how to set up a VPN on your VPS covers the basics. This option gives you real port 25 on a clean IP while your mailboxes and storage stay on Harborvm.
Option A is less to run. Option B gives you more control and no monthly relay fee beyond the helper VPS. Both avoid the one thing you cannot do, which is accept raw port 25 straight onto your VM here.
Reading mail: webmail and mail apps
Once mail lands on the server, you still need to read it. Two paths cover every device.
Webmail on your domain. Install Roundcube or SnappyMail, or use the webmail that ships with Mailcow. Harborvm serves websites on your own domain with automatic HTTPS, so you get https://mail.yourdomain.com with a valid certificate and no extra work. Webmail needs no special ports beyond 443, which is open through a forward.
Mail apps on your phone and laptop. Thunderbird, Apple Mail and Outlook all connect over IMAP for reading and SMTP submission for sending. Map a forwarded port to IMAPS (993) and another to submission (587 or 465) on the VPS, then enter those in the app. Because these are high, authenticated ports, the port 25 block never touches them.
Keep your own copies of important mail. Harborvm does not offer backups or snapshots, so set up your own: export mailboxes on a schedule, or sync the mail store to storage off the VPS. Running your mail data without a backup plan is the fastest way to lose years of correspondence to a single mistake.
When a hosted mailbox is the simpler choice
Self-hosting mail is a real commitment. You maintain the server, watch the authentication records, handle the relay, and keep your own backups. For a small team that just needs a few reliable mailboxes, that is a lot of moving parts for a result a hosted provider gives you out of the box.
Use a hosted mailbox such as Zoho Mail or Google Workspace when:
- You need a handful of human mailboxes more than you need control.
- You do not want to think about deliverability, blocklists or DNS at 2 a.m.
- Your volume is low and steady, not bursts of automated mail.
Self-host on a VPS when you want full control of the data, large volumes of transactional or automated mail, or a setup that must live alongside other services you already run. A common split works well: hosted mailboxes for the humans, and a VPS relay for your application's automated mail. The VPS handles the bulk sending through a smarthost, and your people keep their normal inboxes.
If you decide to self-host, Harborvm fits the parts that matter: a dedicated vCPU so mail processing is not starved, a private network with WireGuard for the inbound tunnel, and HTTPS on your own domain for webmail. Start with a Small or Medium plan, build the sending path first, confirm your test mail lands in a real inbox, then add receiving. Get one message delivered cleanly before you move your whole domain.
Frequently asked questions
Can I run a mail server on a VPS if port 25 is blocked?
Yes. Send outbound mail through a smarthost on port 587 or 465 instead of 25, and receive mail by pointing your MX record at an inbound relay that forwards to a high port you open on the VPS.
Why is outbound port 25 blocked on most VPS hosts?
Port 25 is the path spammers abuse, so hosts block it to protect the reputation of their shared IP addresses. Harborvm blocks it too. Use a relay on 587 or 465 instead.
Do I need SPF, DKIM and DMARC to send email?
In practice, yes. Without them most inbox providers will treat your mail as suspicious. SPF, DKIM and DMARC are defined in public IETF standards and your relay provider gives you the exact records to publish.
When should I use a hosted mailbox instead of self-hosting?
If you need a handful of reliable mailboxes and do not want to manage deliverability, Zoho or Google Workspace is simpler. Self-host when you want full control or large volumes of automated mail.