- a closer look at SMTP


Simple Mail Transfer Protocol has been around for a long time and although it has been revised, extended and abused beyond its original intent, it does remain relatively simple.

If you want to send an email to your client first needs to use DNS to discover where to send the email. This information is stored within the MX record, i.e. for

;                   IN      MX

;; ANSWER SECTION:            10800   IN      MX      20            10800   IN      MX      10

;; ^ domain             ^ ttl            priority^ ^server

Lower priority MX records should be attempted first.

Once the Mail eXchange has been identified the client can attempt to connect and begin. SMTP uses a text based protocol, much like many other protocols of it’s era (looks at FTP & HTTP) Typically an SMTP submission looks like so:

# >>> denotes client message
# <<< denotes server message

<<< 220 My Fancy SMTP server welcome message
>>> EHLO <FQDN or Address>
<<< 250 Greetings

# foreach email do
	>>> MAIL FROM: <>
	<<< 250 OK
	# foreach recipient do
		>>> RCPT TO: <>
		<<< 250 OK
	# end foreach
	>>> DATA
	<<< 354 End data with <CR><LF>.<CR><LF>
	>>> <Headers and Email>
	>>> .
	<<< 250 OK
# end foreach

>>> QUIT
<<< 221 Ciao

Submission and Relay#

Submission is the starting point for an email, an email client connects to the SMTP server (typically port 587). Relay is when SMTP servers pass emails with each other over port 25, i.e. when gmail sends me an email, their SMTP servers will connect to on port 25.

There are other protocols for receiving emails as a client, such as IMAP and POP.


During an SMTP exchange the server can reject the message at various stages, below are some examples:

  • <FQDN or Address> given found in a Block List
  • <MAIL FROM> is blacklisted.
  • <MAIL FROM> SPF denies sending via <FQDN or Address>
  • There is no route to <RCPT TO> via this MX
  • <Headers and Email> rejected (Spam filter, DKIM failure, etc)