How to Receive Email on a VPS Without Running a Full Mail Server
How to Receive Email on a VPS Without Running a Full Mail Server
Sooner or later a server needs to receive email. A monitoring box that should get alerts, a side project that needs signup confirmations, a personal domain where you want a throwaway address. The usual advice is a stack: Postfix, Dovecot, MySQL for virtual users, SPF/DKIM/DMARC, TLS certificates, spam filtering. That is a weekend project, and most of it is unnecessary for receiving a handful of messages.
This is the minimal path: a domain pointed at your VPS, port 25 reachable, and a small SMTP receiver that stores messages. No mail server suite, no database of virtual users.
What you actually need
Four things, in order:
- A domain whose MX record points at your VPS (or a hostname resolving to it).
- Port 25 inbound open on the VPS firewall — receiving mail happens on 25, not 587 or 993.
- A process listening on port 25 that speaks SMTP. This is the part people over-engineer.
- Storage — SQLite, files, whatever — so messages survive the connection.
Optional but important later: SPF/DKIM/DMARC for outbound mail, and a TLS certificate if you also want to send. For receiving only, neither blocks you.
Step 1: the MX record
At your DNS provider, add:
| Type | Name | Value | Priority | |---|---|---|---| | MX | @ | mail.example.com | 10 |
And make sure mail.example.com resolves to the VPS IPv4 address (an A record). If the domain uses a CDN with its own MX management (Cloudflare Email Routing, for instance), turn that off for the subdomain or the record will not apply.
Check it before going further:
dig +short MX example.com
dig +short A mail.example.com
Step 2: open port 25
Most VPS providers block or throttle port 25 by default — open a ticket if you cannot reach it. On the server:
firewall-cmd --add-port=25/tcp --permanent
firewall-cmd --reload
ss -ltn | grep :25
Test from outside with any SMTP tool — telnet, swaks, or a one-off connection. If the connection times out, the block is upstream (provider) or in your firewall; if it connects and hangs, the port is open but nothing is listening yet.
Step 3: something to answer SMTP
A receive-only SMTP server needs to handle a small slice of RFC 5321: EHLO, MAIL FROM, RCPT TO, DATA, QUIT. That is genuinely all an inbound-only service needs. You can write it in ~150 lines of Node.js with node:net (I did — the state machine and the dot-stuffing gotchas are in a separate write-up), or use a small library.
The two mistakes that bite immediately:
- Line buffering. Sockets deliver chunks, not lines. Buffer, split on
\r\n, tolerate bare\n. - Dot-stuffing. In
DATAmode, a line consisting of a single dot ends the message. Clients escape real dots with an extra dot; you must strip one back.
If you would rather not write it: run Postfix on port 25 and relay to your receiver on an internal port (/etc/postfix/transport, smtp:[127.0.0.1]:2527). Postfix then handles TLS, connection hygiene, and reputation for outbound if you ever need it — but you still avoid running a full mailbox setup.
Step 4: catch-all, because addresses are infinite
For a temp-mail style service, you do not want to pre-create mailboxes. Accept everything at the domain:
- With a custom receiver: accept any
RCPT TOwhose domain matches, store under the local part. - With Postfix in front: add the domain to
relay_domainsand map it viatransport. Watch out — if the same domain is listed invirtual_mailbox_domains, Postfix validates each recipient against its mailbox table at SMTP time and rejects unknown addresses with550 5.1.1 User unknown in virtual mailbox table. That exact bug cost me an afternoon: everything tested fine until a real sender tried a freshly generated address.
Step 5: storage and retention
Write messages to SQLite (one table: session, address, subject, headers, bodies) and give each a TTL. A sweeper delete on a timer keeps the disk bounded without crontab gymnastics. For a receiver handling a few messages a minute, SQLite is more than enough — Postfix's own queue files are more complex than what you need.
What this setup does not do
Be honest about the gaps:
- No TLS on port 25 unless you add STARTTLS or front it with Postfix. Many senders connect anyway; some do not.
- No SPF/DKIM verification. Inbound mail can claim any sender. For a throwaway inbox that is acceptable; for anything you trust, add a real MTA in front.
- No outbound. This is receive-only by design.
- No spam filtering. A public catch-all domain will eventually receive spam; plan a filter or a short TTL.
When is this the right call?
If you need to receive a few messages on your own domain — signup codes, alerts, a disposable address — this is the lightest possible setup: one MX record, one port, one small process, one SQLite file. If you need full mailboxes with IMAP, calendars, and sending, install the real stack (or pay for it).
The service running at https://howtageek.com is exactly this setup: an embedded SMTP receiver behind Postfix, SQLite inboxes with a sliding TTL, and no mail-server suite in sight.