How email works: SMTP, IMAP and MX
When you press Send, your message passes through several servers, each speaking a different protocol, before someone reads it. This guide walks through that journey and uses a few read-only checks to see each piece for yourself. You will not send anything yet.
Before you begin
- A VPS running Ubuntu 24.04 LTS, with SSH access as a sudo user (this guide uses
alex). - No mail server is needed. Every check here only reads public information or tests whether a port is open.
- The example domain
example.organd mail hostmail.example.netstand in for a real domain. Substitute your own when you try these commands for real.
Step 1: Install the lookup tools
dig asks DNS servers for records, nc (netcat) tests whether a network port accepts connections, and openssl is already installed on Ubuntu for testing secure connections.
sudo apt update
sudo apt install -y dnsutils netcat-openbsd
Step 2: Find the receiving mail servers (MX records)
Email is addressed to a domain, not a server. The domain's DNS publishes MX records, which name the servers that accept mail for it. The number in front is a priority: lower numbers are tried first.
dig MX example.org +short
10 mail.example.net.
If a domain has no mail service, you may see a special "null MX" record of 0 ., which tells senders that mail is not accepted.
Step 3: Read the sender-policy records (SPF and DMARC)
Receiving servers check whether a sender is trusted. Domains publish that policy as TXT records. SPF lists which servers may send mail for the domain. DMARC tells receivers what to do when checks fail.
dig TXT example.org +short
dig TXT _dmarc.example.org +short
"v=spf1 mx -all"
"v=DMARC1; p=reject; rua=mailto:postmaster@example.org"
Read the SPF line as "only the domain's MX servers may send mail, and reject everything else". DKIM, the third check, uses a signature stored under a selector name; you will meet it when you configure your own server.
Step 4: Check that port 25 is reachable
Servers deliver mail to each other on port 25, using the protocol called SMTP. The -z flag only tests the connection, without sending any data, and -v prints the result.
nc -vz mail.example.net 25
Connection to mail.example.net (203.0.113.25) 25 port [tcp/smtp] succeeded!
Step 5: Speak SMTP by hand
SMTP is a plain-text conversation. Connect to port 25 with nc. The server speaks first with a greeting. You then type the commands below, each followed by Enter. This example only greets the server and quits, so nothing is sent.
nc mail.example.net 25
220 mail.example.net ESMTP ready
Type these lines, pressing Enter after each:
EHLO test.example.com
QUIT
250-mail.example.net
250-PIPELINING
250 8BITMIME
221 2.0.0 Bye
EHLO introduces your client, and QUIT ends the session. A real message adds MAIL FROM, RCPT TO and DATA lines in the same pattern.
Step 6: Check the reading side (IMAP on port 993)
Once a message arrives, the recipient reads it with a mail app that uses IMAP, usually on port 993 over an encrypted connection. This command opens that connection and shows the server's greeting:
openssl s_client -connect mail.example.net:993 -quiet
* OK [CAPABILITY IMAP4rev1 ...] Dovecot ready.
Press Ctrl+C to disconnect. The greeting confirms that a reading service is listening and encrypted.
Troubleshooting
- dig returns nothing. The domain has no record of that type, or you misspelled it. Try
dig example.orgto see the full answer. - nc hangs and then times out. The port is closed, filtered, or blocked by your provider. Check the server's own firewall with
sudo ufw status, then ask LightServe support if outbound port 25 is the problem. - "command not found: dig". Install the tools in Step 1.
- openssl shows a certificate warning. A test server may use a certificate that does not match the name you used. For a quick check, the greeting is still the useful part.
Next steps
You have now seen every stage a message passes through: DNS points to the receiving server, SMTP carries the message between servers, and IMAP lets the recipient read it. The next guide, Install Postfix on your VPS, sets up the SMTP side on your own server.
Something not working? Chat or email our support team and we will help you get unstuck.
Contact support