Sub topic 1
From your server to the recipient's mailbox provider
Prerequisites
This chapter assumes you already know the following:
- What a sender, a recipient, and an ESP (email service provider) or SMTP server are.
- What a DNS record is, and how to read an
MXorTXTrecord. - The difference between transactional email (receipts, password resets) and marketing email (newsletters, promotions).
You do not need to know how SPF, DKIM, or DMARC work yet. Later chapters cover them. Here you only need to know where in the journey they get checked.
Why the path matters
Inbox placement is decided by the receiving mailbox provider, such as Gmail, Outlook.com, or Yahoo. Your server does not decide it. Before you can reason about reputation, engagement, or filters, you need to know which steps happen before a message reaches a mailbox and what the receiver can see at each step.
The receiver is also making decisions during the SMTP conversation itself, before the message body has arrived. Many placement problems show up at that stage, not in the spam folder.
The parties involved
Four roles take part in a typical delivery:
- MUA (mail user agent): the app or code that composes the message, such as a web app, a marketing tool, or a mail client.
- Sending MTA (mail transfer agent): the server that queues the message and delivers it to the recipient's side. If you use an ESP, this is the ESP's server, not yours.
- Receiving MTA: the server at the mailbox provider that accepts or refuses the message.
- Mailbox store: where accepted mail is kept, sorted into the inbox, the spam folder, or other tabs.
The sending MTA is the party the receiver actually talks to. Its IP address, its connection behavior, and the domain names it presents are what the receiver judges first. This is why a shared ESP's reputation can affect you.
Step by step: one delivery
The journey for a message from [email protected] to [email protected] runs as follows.
- Submission. Your application hands the message to the sending MTA, usually over SMTP submission (port 587 with authentication) or through an ESP's HTTP API.
- Queueing. The MTA places the message in a queue. Delivery is asynchronous, so your app being told "sent" only means "queued".
- MX lookup. The MTA looks up the
MXrecords forrecipient.exampleand tries the lowest-preference host first. - Connection. The MTA opens a TCP connection to port 25 on that host. The receiver already sees your IP address and can check it against blocklists and reverse DNS.
- SMTP conversation. The two servers exchange commands. The receiver can refuse at any command.
- Post-acceptance filtering. If the receiver accepts the message, it runs authentication checks, spam filters, and reputation lookups, then picks a folder.
- Mailbox delivery. The message is stored. Recipient actions after that (opening, replying, deleting, reporting spam) feed back into reputation.
Looking at the MX lookup
You can reproduce step 3 from a terminal:
dig +short MX gmail.comThe output lists preference numbers and hostnames. A lower number means higher priority. If the first host is unreachable or answers with a temporary error, the sending MTA tries the next one.
The SMTP conversation
This transcript shows the commands and replies from step 5. Lines starting with S: come from the sending MTA and lines starting with R: come from the receiver. The hostnames are placeholders.
R: 220 mx.recipient.example ESMTP ready
S: EHLO mta1.example.com
R: 250-mx.recipient.example
R: 250 STARTTLS
S: STARTTLS
R: 220 Ready to start TLS
S: MAIL FROM:<[email protected]>
R: 250 OK
S: RCPT TO:<[email protected]>
R: 250 OK
S: DATA
R: 354 End data with <CR><LF>.<CR><LF>
S: (headers and body, ending with a line containing only a period)
R: 250 2.0.0 Message accepted for delivery
S: QUIT
R: 221 ByeThree details matter for placement:
- The EHLO name.
mta1.example.comshould resolve in DNS to the connecting IP address, and the IP should have a reverse DNS (PTR) record pointing back to a matching name. Mismatches are a common cause of early rejection. - The envelope sender.
MAIL FROMsets the bounce address (also called the Return-Path). SPF is checked against this domain. It can differ from the visibleFrom:header the recipient sees. - The visible From. The
From:header is inside theDATAsection. DMARC compares it with the domains authenticated by SPF and DKIM. This is why the envelope and header domains both matter.
Reading the reply codes
Every SMTP reply starts with a three-digit code. The first digit tells your MTA what to do next.
| Code range | Meaning | What the sender should do |
|---|---|---|
| 2xx | Accepted | Treat the message as handed off. This is not a promise of inbox delivery. |
| 4xx | Temporary failure | Keep it queued and retry later with backoff. |
| 5xx | Permanent failure | Stop retrying. Record the failure and suppress the address if it is a bad mailbox. |
Enhanced status codes such as 5.1.1 (mailbox does not exist) or 5.7.1 (blocked for policy reasons) add detail. Read the human-readable text too. Providers often include a URL that names the exact policy you broke.
Here is the handling logic in Python. The same function appears again when we discuss bounces.
def classify_smtp_reply(code: int) -> str:
"""Map an SMTP reply code to a handling decision."""
if 200 <= code < 300:
return "accepted"
if 400 <= code < 500:
return "retry_later" # temporary failure (4xx)
if 500 <= code < 600:
return "suppress" # permanent failure (5xx)
return "unknown"
print(classify_smtp_reply(250)) # accepted
print(classify_smtp_reply(451)) # retry_later
print(classify_smtp_reply(550)) # suppressWhere the receiver can decide
The receiver can act at several points. Knowing which one fired narrows down the cause of a problem.
| Point | What the receiver knows | Typical outcome |
|---|---|---|
| Connection | Sending IP, reverse DNS, blocklist status, connection rate | Refuse the connection or answer 4xx |
| After `EHLO` and `MAIL FROM` | HELO name, envelope domain, SPF result | Refuse the sender |
| After `RCPT TO` | Whether the mailbox exists | `550` for unknown user |
| After `DATA` | Full headers and body, DKIM result, DMARC result, content | Reject, accept to spam, or accept to inbox |
| After acceptance | Recipient behavior over time | Move, relabel, or adjust reputation |
Rejecting during the conversation is cheap for the receiver and gives you an immediate, visible reply. Filtering after acceptance is silent. The sender gets 250 and the message may still go to spam. That difference is why the next chapter separates inbox, spam folder, and rejection.
Edge cases
- Greylisting. Some receivers answer the first attempt from an unknown sender with a temporary
4xx, expecting a real MTA to retry. A proper MTA retries and the message gets through, with a delay. A script that treats any non-2xx as a final failure loses the message. - Retry windows. MTAs usually retry for several days, with growing gaps. After that, they give up and generate a bounce. A long retry queue to one provider is a warning sign that the provider is throttling you.
- Throttling. Replies such as
421 4.7.0 try again latermean the provider is limiting your rate, often because of reputation. Pushing harder makes it worse. - Asynchronous bounces. Some receivers accept the message with
250and later send a separate bounce message to the envelope sender. Your bounce handling must read those, not only the live SMTP replies. - Forwarding and intermediaries. If a message passes through a forwarder or mailing list, the final receiver may see a different connecting IP than the original sender's. This can break SPF. DKIM often survives, which is one reason to sign your mail.
- Shared and dedicated IPs. On a shared ESP IP, the receiver sees the reputation of everyone using it. On a dedicated IP, it sees only yours, and you have to build it. Chapter four on identity returns to this.
- IPv6. Receivers often apply stricter rules to IPv6 senders, such as requiring valid reverse DNS and judging reputation per network block.
What to take into the next chapter
The receiver sees your IP address and your domains before it sees your content. It can refuse at several points. A 250 means only that the message was accepted for handling. The next chapter looks at what happens after that, and at how inbox, spam folder, and rejection differ in what they tell you.
Exercise
Your ESP's logs show 250 2.0.0 Message accepted for a campaign to a large provider, but several recipients say it landed in spam. Which stage of the path decided that, and why did your sending side not see an error?
Show answer
The decision came after the SMTP conversation, in the receiver's post-acceptance filtering (authentication, reputation, and content checks, followed by folder selection). The receiving MTA had already replied 250, which only means it accepted the message for handling. Spam foldering is silent, so no SMTP error is returned to the sender.
Exercise
An SMTP reply to a message is 451 4.7.1 Greylisted, please retry in 300 seconds. What should your MTA do, and what should it not do?
Show answer
It should keep the message in the queue and retry after the delay, because 4xx is a temporary failure. It should not treat the reply as a permanent failure, drop the message, or suppress the recipient address.