Simple Mail Transfer Protocol(SMTP) and POP3、IMAP

Source: Internet
Author: User
Keywords simple mail transfer protocol (smtp) smtp simple mail transfer protocol definition what is simple mail transfer protocol smtp
A network composed of a large number of mail servers. Here, the commonly used Simple Mail Transfer Protocol (SMTP) is used as the mail sending protocol, and the commonly used POP3 is used as the mail reading protocol. Please note that both SMTP and POP3 (or IMAP) use TCP connections to transmit mail. The purpose of using TCP is to transmit mail reliably.

Alibaba Cloud Simple Application Server:  Anti COVID-19 SME Enablement Program
$300 coupon package for all new SMEs and a $500 coupon for paying customers.

User Agent UA (User Agent)
The user agent is the interface between the user and the e-mail system. In most cases, it is a program running on the user's computer. Therefore, the user agent is also called e-mail client software.

User agents provide users with a very friendly interface (currently mainly a window interface) to send and receive mail. There are many types of user agents available for everyone to choose from. For example, the more popular Outlook and Foxmail.

The user agent should have at least the following four functions.

write. Provide users with an environment for editing letters. For example, users should be able to create an easy-to-use address book (with common names and addresses). When replying to a letter, it is not only convenient to extract the address of the other party from the letter, and automatically write this address into the appropriate place in the mail, but also to reply to the questions raised by the letter (the system will automatically copy a copy of the letter) In the window where the user composes the reply, the user does not need to enter the question in the letter).

display. The letter can be easily displayed on the computer screen (including the sound and image attached to the letter).

deal with. Processing includes sending and receiving mail. The recipient should be able to process the letter in different ways according to the situation. For example, after reading, delete, save, print, forward, etc., and self-created directories to classify and save incoming letters. Sometimes you can also check the sender and length of the mail before reading the letter. For unwilling to receive the letter, you can delete it directly in the mailbox.

Communication. After the sender finishes composing the email, he should use the email sending protocol to send it to the mail server used by the user. When the recipient receives the mail, the mail reading protocol is used to receive the mail from the local mail server.


Mail Server

The function of the mail server is to send and receive mails, and at the same time report the results of mail delivery (delivered, rejected, lost, etc.) to the sender. The mail server works in accordance with the client server mode (C/S). The mail server needs to use two different protocols. One protocol is used by user agents to send mail to or between mail servers, such as the SMTP protocol, while the other protocol is used by user agents to read mail from the mail server, such as the post office protocol POP3.

It should be noted here that the mail server must be able to act as both a client and a server. For example, when mail server A sends mail to another mail server B, A acts as an SMTP client and B is an SMTP server. Conversely, when B sends an email to A, B is the SMTP client and A is the SMTP server.

Mailing agreement
Here is the simple mail transfer protocol SMTP speaking-
SMTP specifies how information should be exchanged between two communicating SMTP processes. Since SMTP uses a client-server method, the SMTP process responsible for sending mail is the SMTP client, and the SMTP process responsible for receiving mail is the SMTP server. As for the internal format of the mail, how the mail is stored, and how fast the mail system should send the mail, SMTP has not made regulations.

After the sender's mail is sent to the mail cache of the sender's mail server, the SMTP client scans the mail cache at regular intervals. If mail is found, use the well-known port number 25 of SMTP to establish a TCP connection with the SMTP server of the receiving mail server.
After the connection is established, the recipient SMTP server will send out "220 Service ready". Then the SMTP client sends a HELO command to the SMTP server with the host name of the sender. If the SMTP server has the ability to receive mail, it will answer: "250 OK", indicating that it is ready to receive. If the SMTP server is unavailable, answer "421 Service not available". If the mail cannot be sent within a certain period of time, the mail server will notify the sender of this situation.

SMTP does not use an intermediate mail server. No matter how far apart the mail servers of the sender and the receiver are, and no matter how many routers have to be traversed during the mail transmission, the TCP connection is always established directly between the two mail servers of the sender and the receiver. When the recipient's mail server fails and cannot work, the sender's mail server can only wait for a period of time before trying to establish a TCP connection with the mail server, instead of finding an intermediate mail server to establish a TCP connection.

The transmission of mail starts with the MAIL command. The MAIL command is followed by the sender's address. For example: MAIL FROM:xxxx@huawei.com. If the SMTP server is ready to receive mail, then answer "250 OK". Otherwise, return a code indicating the reason.

451 (error during processing), 452 (not enough storage space), 500 (unrecognized command).
The following is followed by one or more RCPT commands (abbreviation of recipient), which depends on sending the same message to one or more recipients. The format is RCPT TO: <recipient address>. The function of the RCPT command is to find out if the recipient's system is ready to receive mail before sending the mail. This is done to avoid wasting communication resources, so that the address error will not be known after sending a long email.
Every time a RCPT command is sent, there should be corresponding information returned from the SMTP server, such as: "250 OK", indicating that the specified mailbox is in the recipient's system, or "550 No such user here" (no such user here), that is This mailbox does not exist.

The following is the DATA command, which means that the content of the mail will start to be transmitted. The message returned by the SMTP server is: "354 Start mail input; end with<CRLF>.<CRLF>". Here <CRLF> means "carriage return and line feed". If the mail cannot be received, it returns 421 (the server is unavailable), 500 (the command cannot be recognized), etc.
Then the SMTP client sends the content of the email. After sending, send <CRLF>.<CRLF> (separated by a dot between two carriage returns and line feeds) to indicate the end of the email content. In fact, the printable character seen on the server side is only an English period. If the mail is received, the SMTP server will return the message "250 OK" or return an error code.

Finally, after the mail is sent, the SMTP client should send the QUIT command. The message returned by the SMTP server is "221 (service off)", indicating that SMTP agrees to release the TCP connection. The entire process of mail transmission ends.

Here again, users using e-mail cannot see these processes, and all these complex processes are blocked by e-mail user agents.
Mail reading protocol
There are two commonly used mail reading protocols, namely the third version of the Post Office Protocol POP3 and the Internet Message Access Protocol
IMAP (Internet Message Access Protocol).

POP3
Post Office Protocol POP is a very simple, but limited function mail reading protocol. The post office agreement POP was originally published in 1984. After several updates, it is now the 1996 version of POP3 [RFC 1939], which has become the official Internet standard.

The user agent in the user's computer receiving the mail must run the POP3 client program, and the POP3 server program should be run in the mail server to which the recipient is connected. Of course, this mail server must also run the SMTP server program in order to receive mail from the SMTP client program of the sender's mail server. The P0P3 server only allows the mailbox to be read after the user enters the authentication information (user name and password).

One feature of the POP3 protocol is that as long as the user reads the mail from the POP3 server, the POP3 server deletes the mail. This is not convenient in some cases. For example, a user receives an e-mail on a desktop computer in the office and has no time to write a reply, so he immediately carries a laptop computer on a business trip. When he opened his laptop and wrote back, the POP3 server had deleted the emails he had read (unless he copied them to the laptop in advance). In order to solve this problem, POP3 has carried out some function expansions, including allowing users to set the time that mails are still stored in the POP3 server after reading [RFC2449]. RFC2449 is currently the Internet recommended standard.

IMAP
Another protocol for reading mail is the Internet Message Access Protocol IMAP, which is much more complicated than POP3. Both IMAP and POP work as client-server, but they are quite different. The newer version is version 4 revised in March 2003, namely IMAP4 [RFC3501], which is currently the recommended standard for the Internet. However, in practice, we rarely add the version number "4" to this protocol, and often simply use IMAP for IMAP4. But for POP3, you will not forget to write the version number "3".

When using IMAP, run the IMAP client program on the user's computer, and then establish a TCP connection with the IMAP server program on the recipient's mail server. Users can manipulate the mailbox of the mail server on their own computers, just as they do locally, so IMAP is an online protocol.

When the IMAP client program on the user's computer opens the mailbox of the IMAP server, the user can see the header of the mail. If the user needs to open a certain mail, the mail will be delivered to the user's computer. Users can create hierarchical mailbox folders for their own mailboxes according to their needs, and they can move the stored messages from one folder to another. The user can also search the mail according to a certain condition. The mail in the mailbox of the IMAP server is kept until the user issues a command to delete the mail.

The biggest advantage of IMAP is that users can use different computers in different places (for example, use the computer in the office, or the computer at home, or use the laptop in the field) to read and process their mail in the mail server at any time.

IMAP also allows recipients to read only a certain part of the message. For example, I received an email with a video attachment (this file may be very large), and the user uses wireless Internet access, and the channel transmission rate is very low. In order to save emails with attachments (this file may be very large), and users use wireless Internet access, the channel transmission rate is very low. To save time, you can download the body of the email first, and then read or download this large attachment when you have time.

The disadvantage of IMAP is that if the user does not copy the mail to his computer, the mail is always stored on the IMAP server. To check your own mail, you must first go online.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.