People send messages via electronic mail to each other by various methods on the mainframe computers until the SMTP protocol came. In August 1982 Information Sciences Institute proposed the standard method for sending and receiving emails which was called as the simple mail transfer protocol. Soon it became very popular on the Arpanet by replacing the older complicated methods for sending emails. Even though the protocol has been revised and extended regularly since that time the fundamental method for sending the mails remained unchanged. This protocol is a text-based protocol which originally does not support the delivery of binary data and however this made the protocol to be easy for the implementation and maintaining. Later multipurpose internet mail extensions (MIME) became popular in the 80s for encoding and sending the binary data via this protocol.
Today SMTP remains the dominant protocol in the internet for sending and receiving emails. Since this protocol is text-based, learning it is very easy when compared with many others. All it requires to communicate with an SMTP server is a program capable of sending the ASCII data over the TCP/IP port 25.
Email is sent via this protocol in a transaction i.e., if the process of sending the messages is not completed in full then without generating any error the message is dropped. Transaction has three stages:
- Specifying a sender,
- Provide one or more recipients,
- Send a message.
But SMTP transaction has five stages:
- Send reply address
- Send recipients
- Send message data
- End transaction
When connecting to Simple Mail Transfer Protocol SMTP Servers on port 25, the sender must wait for the receiver to accept the connection and identify itself like in the format:
220 [domain] [Service Information]
Then the sender must identify it to the receiver using the HELO command:
The mail servers will expect each to identify it using the domain name that could be used to verify the identity of the server by performing an MX record lookup. But the receiving server should not reject the connection during this stage even if the identity of the sender could not be verified and so should reply with:
250 reply code from an SMTP server is the generic ok response to say the last action completed successfully.
Send reply address:
After the two servers have performed the handshake, the transaction has started and so the commands can be sent to the servers. Suppose if you want to know the commands supported by the server, then you can send the command HELP and the server will respond with a detailed message of the commands supported. To send a message to any user on this server, the reply address must be set first so that if any errors that occur during the transaction can be reported to this address, and for that MAIL FROM command is used.
After providing the reply address, SMTP should allow to identify the recipient(s) of the message which can be done by using the command RCPT TO. In order to set the multiple recipients you can simply repeat this command for each recipient. If the receiver accepts the mail for this user at this time, then it can be replied with a 250 ok reply. But if the mail is not accepted, a 550 failure reply or the appropriate error code will be sent. If a 250 Ok reply is received, then the process of sending the message data can be continued.
Send message data:
Sending the data through this protocol is simple but the message formats can be quite complicated particularly when sending binary attachments. In order to start sending the data, DATA command must be sent to the server which must reply with a 354 intermediate reply. For sending the plain text messages, it is not required to use the multi-part MIME message format. All messages are ended by sending a line which contains only a period character.
Ending the transaction:
QUIT command is sent for closing the connection and so the destination server will reply with a 221 reply to confirm the completion of the transaction. If the QUIT command is not sent before the closing of the connection, the destination server will then delete all the stored messages.