SMTP commands are used to sent messages from an email client to another email server. The commands follows optional argument(s):
Keyword : argument(s)
Basic commands
Abbreviation terms:
<SP>: Space
<CRLF>: Enter
Keyword | Command format | Description | Usage |
---|---|---|---|
HELO | HELO<SP><domain><CRLF> | Provides identification (host name) of the sender | Mandatory |
MAIL<SP>FROM:<sender-address><CRLF> | Specifies the sender email address | Mandatory | |
RCPT | RCPT<SP>TO:<forward-address><CRLF> | Specifies the recipient email address | Mandatory |
DATA | DATA<CRLF> | Specifies the beginning of the email | Mandatory |
QUIT | QUIT<CRLF> | Closes the TCP connection | Mandatory |
Termination
To signify the end of the email message, the client sends a period (.
) on a line by itself. The server then acknowledge the successful receipt of the email message.
Multipurpose Internet Mail Extension (MIME)
MIME is a standard that extends the original format of internet email, which initially only supported plain text. MIME adds flexibility to email that allowing the to carry various types of data including multimedia contents (e.g. image, audio, video), formatted text (HTML), and binary files (attachments).
Use case
To use MIME in email the steps are needed to follow.
- Compose the email Compose the email contents including text, formatting, and attachments if any.
- Set MIME header In the email header, specify the MIME version.
MIME-Version: 1.0
- Specify content types For plain text content:
Content-Type: text/plain; charset=utf-8
For HTML content:
Content-Type: text/html; charset=utf-8
For images (e.g. JPEG):
Content-Type: image/jpeg
For attachments (e.g. PDF file):
Content-Type: application/pdf; name="example.pdf"
Content-Disposition: attachment; filename="example.pdf"
- Write body message Write the email contents
- Termination
At the end of the email, use a period (
.
) to indicate the end of the email.
SMTP communication
Talk to an SMTP server
The SMTP uses port 25 for email communication. To initiate a connection, you can use the command line utility telnet
, or openssl
for secure connection.
Using Telnet for plain SMTP connection on port 25
telnet mail.example.com 25
Replace the mail.example.com
with the SMTP server’s hostname or IP address.
After you pressed Enter, you should see a response from the SMTP server indicating that you are connecting successfully, it may look similar to this:
Trying 10.86.166.36...
Connected to mail.example.com.
Escape character is '^]'.
220 staff.mail.example.com. V1.4 ready at Mon, 02 Jul 2012
10:05:29 +1000
Use SMTP protocol
Now you can say hello to the server with the SMTP command:
HELO example.com
You may replace the example.com
with the hostname. In some cases, if you are accessing an internal SMTP server, from out side the corporate or organisation network, you might need to use a VPN to establish a connection to the internal network before accessing the SMTP server.
Continue sending SMTP commands as needed for your specific task, such as sending email.
To quit the SMTP session, you can use QUIT
.
QUIT
Communication senario
Back to parent node: Simple Mail Transfer Protocol (SMTP)
Computer_networks INFO1112 IP_model Application_layer Simple_Mail_Transfer_Protocol_SMTP SMTP_command MultiPurpose_Internet_Mail_Extension_MIME