What SMTP is
SMTP (Simple Mail Transfer Protocol, RFC 5321) carries mail from clients to their server and from one server to another. It is a text dialogue over TCP: the client sends four-letter commands and the server answers with a three-digit code, as in FTP. SMTP only sends: POP3 or IMAP are used to read the mailbox.
It works by store and forward: each server accepts the message, keeps it in its queue and takes care of passing it to the next one, which it finds with the MX record of the recipient's domain.
Ports and roles
| Port | Use | Encryption |
|---|---|---|
| 25 | Between servers (MTA to MTA); also network devices and applications inside the network | Optional STARTTLS (opportunistic) |
| 587 | Sending from clients (submission), with user name and password | STARTTLS, usually required |
| 465 | Sending from clients with implicit TLS (RFC 8314) | TLS from the first byte |
Many ISPs block outbound port 25 on residential connections to curb spam: mail clients use 587 or 465.
How it works: from the applet to the mailbox
Seven steps: the connection, the greeting, the envelope, the message, the close, the MX record and the relay with STARTTLS.
The alert: EEM opens TCP 25
Gi0/0/3 goes down and R1 logs %LINK-3-UPDOWN. The WAN-TOR-CAIDA applet has an event syslog pattern that matches that text, so it runs its mail action: it opens a TCP connection to port 25 on mx2 (192.168.20.25). The IOS SYN carries only the MSS option. Once the connection is open, the server speaks first: 220, service ready, with its name and its software (ESMTP Postfix).
HELO: R1 introduces itself
R1 sends HELO R1. HELO is the basic SMTP greeting; with EHLO, the extended SMTP greeting, the server would answer with its list of extensions (you will see it in step 7). RFC 5321 asks for a fully qualified name (FQDN), and some servers reject a short name like R1; Postfix, with its default settings, accepts it and answers 250 with its own name.
MAIL FROM and RCPT TO: the envelope
SMTP separates the envelope from the message, like a letter: MAIL FROM says who is sending (and where error notices go back) and RCPT TO, who it is delivered to. Servers deliver according to the envelope, not the message's From: and To: headers. mx2 accepts the sender (250 2.1.0) and the recipient (250 2.1.5): R1 is in its mynetworks and the canada-logistica.example domain is in its relay_domains. In the enhanced code, the middle 1 (2.1.x) means the reply is about an address.
DATA: the message and the final period
R1 sends DATA and mx2 answers 354: go ahead, and end with <CR><LF>.<CR><LF>. Then the message arrives in RFC 5322 format: the From, To and Subject headers, an empty line and the body, which is the syslog message ($_syslog_msg). A line with a single period marks the end. mx2 stores the message in its queue and answers 250 2.0.0 Ok: queued as 6B1E42A0C3. It all travelled unencrypted: anyone who captures the traffic reads the whole alert.
QUIT: the message stays in the queue
R1 sends QUIT and mx2 says goodbye with 221 2.0.0 Bye. For R1, the job ended with the 250 "queued": from that moment, delivering the message is mx2's responsibility. That is how SMTP works: store and forward. If Montreal did not answer, mx2 would keep the alert in its queue and retry for days (5 by default in Postfix) before bouncing it.
The MX record: who gets the mail?
To deliver to noc@canada-logistica.example, mx2 asks DNS for the domain's MX record. The answer has two: MX 10 mx1 and MX 20 mx2. The lowest value wins and, on top of that, mx2 finds itself in the list: under RFC 5321, it drops its own entry and any with an equal or higher preference, so it does not deliver the mail to itself. That leaves mx1, so it asks for its A record: 10.20.30.25. This is the use of the MX record that CCNA v2.0 topic 4.4 asks about.
Relay to mx1 with EHLO and STARTTLS
mx2 opens a TCP connection to port 25 on mx1 (between two Linux hosts, with timestamps and window scaling) and greets it with EHLO. mx1 answers with a multiline 250: its name and its extensions, including STARTTLS and SIZE 10240000. Because mx2 has smtp_tls_security_level = may (opportunistic TLS), it sends STARTTLS; mx1 answers 220 Ready to start TLS and the next thing on the connection is the ClientHello: the envelope and the message travel encrypted. R1's alert, on the other hand, travelled in clear text; EEM can send it encrypted on port 587 (port 587 secure tls).
The MX record and preference
| Record | Value | What it means |
|---|---|---|
| MX 10 | mx1.canada-logistica.example | Main server: the lowest preference |
| MX 20 | mx2.canada-logistica.example | Backup: used if mx1 does not answer |
| A | mx1 → 10.20.30.25 | The address the delivering server connects to |
An MX points to a name, never to an IP or an alias (CNAME). If several MX records share the same preference, the sender spreads mail across them. If the domain has no MX, RFC 5321 allows using its A or AAAA record. The DNS lab shows this same query with dig.
The replies
| First digit | Meaning | Examples |
|---|---|---|
| 2xx | Completed successfully | 220, 250 and 221 in this lab |
| 3xx | Continue: the server expects more data | 354 End data with <CR><LF>.<CR><LF> |
| 4xx | Temporary error: the sender retries later | 421 service not available, 450 mailbox unavailable |
| 5xx | Permanent error: the message bounces | 550 no such mailbox, 554 transaction failed |
The RFC 3463 enhanced codes, such as 2.1.5 or 5.7.1, add detail in three parts: the class, the subject (1 = address, 7 = security or policy) and the specific case.
Safer email
| Mechanism | What it does |
|---|---|
| STARTTLS (RFC 3207) | Encrypts the connection if both sides support it; without checking the certificate, it only protects against eavesdroppers |
| MTA-STS and DANE | Require TLS between servers and certificate verification |
| SPF | Which servers may send mail for a domain (TXT record) |
| DKIM | Signs the message; the public key is in DNS |
| DMARC | What to do if SPF and DKIM fail, published in DNS |
SPF, DKIM and DMARC are DNS records too (TXT): DNS does not only say where to deliver mail, it also helps decide whether it is legitimate.
Email alerts in Cisco IOS XE
| Command | What it does |
|---|---|
event manager applet WAN-TOR-CAIDA | Creates the EEM applet. |
event syslog pattern "Interface GigabitEthernet0/0/3, changed state to down" | It is triggered by a syslog message that matches the pattern. |
action 1.0 mail server "192.168.20.25" to … from … subject … body "$_syslog_msg" | Sends the email over SMTP; $_syslog_msg is the message that triggered it. |
… source-interface Loopback0 | Picks the source interface (by default, the outgoing one). |
… port 587 secure tls | Sends it encrypted; the server is written as user:password@server. |
This lab belongs to the CCNA v2.0 track: topic 4.4 asks you to explain DNS records, MX among them. Seeing the MX lookup inside a real mail delivery shows what it is for.
Frequently asked questions
How do the envelope and the headers differ?
The envelope is MAIL FROM and RCPT TO: servers use it to deliver. The From:, To: and Subject: headers are inside the message and are what the reader sees. They may not match: with a blind copy (Bcc), the recipient is in the envelope but not in the headers.
Why does a period end the message?
Because SMTP is a text dialogue and the server needs to know where the message ends. If a body line starts with a period, the client adds another one (dot-stuffing) and the server removes it.
What happens if mx1 does not answer?
mx2 keeps the message in its queue and retries. And if a server on the Internet sent mail to the domain while mx1 was down, it would use MX 20, mx2, which would hold it until mx1 is back.
Does STARTTLS always protect?
Not entirely: someone on the path can strip STARTTLS from the EHLO reply and the client would carry on in clear text (a downgrade attack). MTA-STS and DANE require TLS and certificate verification.
How do I see the email in Wireshark?
With the smtp or imf filters. In an unencrypted session, File > Export Objects > IMF saves the whole message.
What you take away
- SMTP sends mail with text commands over TCP: port 25 between servers; 587 or 465 from clients.
- The envelope (MAIL FROM and RCPT TO) drives delivery; the headers are what the reader sees.
- The message ends with a line that holds only a period (CRLF.CRLF).
- Each server stores and forwards: the 250 "queued" hands over the responsibility.
- The delivering server looks up the domain's MX record and prefers the lowest value (topic 4.4).
- STARTTLS encrypts the connection; the EHLO reply says whether the server supports it.
NEXT STEP
From this lesson to the CCNA 2.0 Course
Network services and DNS records (topic 4.4) are part of The House of Routing's CCNA 2.0 Course, with EEM and alerts in the Canadá Logística lab. We will let you know when it opens.
Upcoming protocol lessons
Sources
- RFC 5321 · Simple Mail Transfer Protocol
- RFC 5322 · Internet Message Format
- RFC 3207 · SMTP Service Extension for Secure SMTP over TLS (STARTTLS)
- Cisco · Utilize EEM to Automate Secure Emails to an SMTP Server (IOS XE)
- Postfix · postconf(5) (relay_domains, mynetworks, smtp_tls_security_level)
- Cisco · 200-301 CCNA v2.0 Exam Topics (4.4)
Lesson prepared with AI assistance and checked against the sources cited. The bytes of every packet are generated according to the standard and verified with an independent tool.