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
client first needs to use DNS to discover where to send the email. This
information is stored within the MX record, i.e. for
;; QUESTION SECTION: ;lawrence.pm. IN MX ;; ANSWER SECTION: lawrence.pm. 10800 IN MX 20 helo.mx.ax. lawrence.pm. 10800 IN MX 10 ehlo.mx.ax. ;; ^ 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: <email@example.com> <<< 250 OK # foreach recipient do >>> RCPT TO: <firstname.lastname@example.org> <<< 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
ehlo.mx.ax 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: