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
KeywordCommand formatDescriptionUsage
HELOHELO<SP><domain><CRLF>Provides identification (host name) of the senderMandatory
MAILMAIL<SP>FROM:<sender-address><CRLF>Specifies the sender email addressMandatory
RCPTRCPT<SP>TO:<forward-address><CRLF>Specifies the recipient email addressMandatory
DATADATA<CRLF>Specifies the beginning of the emailMandatory
QUITQUIT<CRLF>Closes the TCP connectionMandatory

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.

  1. Compose the email Compose the email contents including text, formatting, and attachments if any.
  2. Set MIME header In the email header, specify the MIME version.
MIME-Version: 1.0
  1. 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"
  1. Write body message Write the email contents
  2. 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_networksINFO1112IP_modelApplication_layerSimple_Mail_Transfer_Protocol_SMTPSMTP_commandMultiPurpose_Internet_Mail_Extension_MIME