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.
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:
Specify your domain name so that the mail server knows who you are.
E.g. HELO example.com
Specify the sender email.
E.g. MAIL FROM: <firstname.lastname@example.org>
Specify the recipient. Issue this command multiple times if you have more than one recipient.
E.g. RCPT TO: <email@example.com>
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."
Terminates the conversation with the server.
Specify that your recipient is a mailing list.
Asks for help from the mail server.
Does nothing except to get a response from the server.
Aborts the current conversation and start a new conversation.
Sends a message to a user's terminal instead of a mailbox.
Sends a message to a user's terminal and to a user's mailbox.
Sends a message to a user's terminal if they are logged on; otherwise, sends the message to the user's mailbox.
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.
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:
System status or system help reply.
Server is ready.
Server transmission ending.
Requested mail action okay, completed.
Specified user is not local, but the server will forward the mail message.
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."
The mail service is unavailable. Try again later.
The recipient mailbox is busy. Try again later.
The requested action was not done. Some error occurred in the mail server.
The requested action was not done. The mail server ran out of system storage.
The last command contained a syntax error or the command line was too long.
The parameters or arguments in the last command contained a syntax error.
The mail server has not implemented the last command.
The last command was sent out of sequence. For example, you might have sent DATA before sending RECV.
One of the parameters of the last command has not been implemented by the server.
The recipient mailbox is not found, no access, or command rejected for policy reasons
The specified user is not local; part of the text of the message will contain a forwarding address.
The recipient mailbox is full. Try again later.
The mail address that you specified was not syntactically correct.
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
250 2.1.0 Ok
250 2.1.5 Ok
354 End data with <CR><LF>.<CR><LF>
This is a test message.
250 2.0.0 Ok: queued as 4227FE00C
221 2.0.0 Bye
Read more about the RFC standards: