SMTP commands according to RFC

SMTP commands according to RFC

What is SMTP?

Simple Mail Transfer Protocol (SMTP) is an Internet standard for sending emails. The original specifications for SMTP was published under RFC 821 in 1982. Later on, additional specifications were introduced under RFC 5321. SMTP by default uses TCP port 25 but may also use port 587. If SSL is used to secure the SMTP transmission then the default port is 465.

SMTP commands

When you send an email, you are actually sending a bunch of commands to the SMTP server. Below are some of the commands that the SMTP server can recognize:

HELO
Specify your domain name so that the mail server knows who you are.
E.g. HELO example.com
MAIL
Specify the sender email.
E.g. MAIL FROM: <example@example.com>
RCPT
Specify the recipient. Issue this command multiple times if you have more than one recipient.
E.g. RCPT TO: <example2@example.com>
DATA
Issue this command before sending the body of the message. The message body must end with the following five letter sequence: “\r\n.\r\n.”
QUIT
Terminates the conversation with the server.
EXPN
Specify that your recipient is a mailing list.
HELP
Asks for help from the mail server.
NOOP
Does nothing except to get a response from the server.
RSET
Aborts the current conversation and start a new conversation.
SEND
Sends a message to a user’s terminal instead of a mailbox.
SAML
Sends a message to a user’s terminal and to a user’s mailbox.
SOML
Sends a message to a user’s terminal if they are logged on; otherwise, sends the message to the user’s mailbox.
TURN
Reverses the role of client and server. This might be useful if the client program can also act as a server and needs to receive mail from the remote computer.
VRFY
Verifies that a particular user name of a given mail address exists. Not supported by all mail servers.

SMTP server replies

Every command will receive a reply from the mail server in the form of a three digit code followed by a description. The code is standard but the description may vary between different mail servers. Below are some of the possible codes & their meanings that a mail server may respond with:

211
System status or system help reply.
214
Help message.
220
Server is ready.
221
Server transmission ending.
250
Requested mail action okay, completed.
251
Specified user is not local, but the server will forward the mail message.
354
This is a reply to the DATA command. After getting this, start sending the body of the mail message, ending with “\r\n.\r\n.”
421
The mail service is unavailable. Try again later.
450
The recipient mailbox is busy. Try again later.
451
The requested action was not done. Some error occurred in the mail server.
452
The requested action was not done. The mail server ran out of system storage.
500
The last command contained a syntax error or the command line was too long.
501
The parameters or arguments in the last command contained a syntax error.
502
The mail server has not implemented the last command.
503
The last command was sent out of sequence. For example, you might have sent DATA before sending RECV.
504
One of the parameters of the last command has not been implemented by the server.
550
The recipient mailbox is not found, no access, or command rejected for policy reasons
551
The specified user is not local; part of the text of the message will contain a forwarding address.
552
The recipient mailbox is full. Try again later.
553
The mail address that you specified was not syntactically correct.
554
The mail transaction has encountered unknown errors.

Typical SMTP conversation

When you make a connection to a mail server, a typical conversation will look like below (BOLD indicates the replies from the server):

220 mx1.example.com ESMTP Postfix
HELO example.com
250 mx1.example.com
MAIL FROM:<example@example.com>
250 2.1.0 Ok
RCPT TO:<example2@example.com>
250 2.1.5 Ok
DATA
354 End data with <CR><LF>.<CR><LF>
This is a test message.
.
250 2.0.0 Ok: queued as 4227FE00C
QUIT
221 2.0.0 Bye

RFC references

Read more about the RFC standards:

Was this article helpful?

Related Articles