Original SMTP command code and working principle

Source: Internet
Author: User
Tags mx record

Original SMTP authorization code and working principle [transfer]-One-Stop Conversion

Http://www.chinaunix.net Author: tutux published at: 16:41:54
[Comment] [View Original] [mail server discussion board] [close]

Original SMTP command code and working principle  

1. SMTP works in two situations: first, email is transmitted from the client to the server; second, transfer data from one server to another
server
2. SMTP is a request/response protocol. commands and responses are based on ASCII text and end with Cr and LF characters. The response includes a three-digit
return status Code
3. SMTP listens for connection requests on TCP port 25
4. connection and sending process:

A. Establish a TCP connection 
B. The client sends the HELO command to identify the sender, and then the client sends the MAIL command 
If the server correctly wishes to use OK as a response, it indicates that it is ready to receive 
C. The client sends the RCPT command to identify the recipient of the email. There can be multiple RCPT lines. 
The server indicates whether the email is willing to be accepted by the recipient. 
D. After the negotiation ends, send an email and use the command data to send it. 
E. End the input content and send it together. 
F. End sending and exit with the quit command. 

5. Two other commands: 
VRFY --- used to verify whether a given user's email address exists and receive detailed information about the user. 
EXPN --- used to expand the mail list. 

6. mail routing process: 
The SMTP server routes emails based on the domain name of the recipient in the 'domain Name Service DNS. The SMTP server is based on the MX record in the DNS 
The MX record registers the domain name and the relevant SMTP relay host. All emails in this domain should be sent to the host. 

If the SMTP server mail.abc.com receives a letter to be sent to the shuser@sh.abc.com: 

A. Sendmail requests DNS to provide the cname record of host sh.abc.com. If yes, if cname is sent to shmail.abc.com 
Request the cname record of shmail.abc.com until no 
B. Assume that the cname is sent to shmail.abc.com, and then the DNS of the Sendmail request @ abc.com domain gives the MX record of shmail.abc.com, 
Shmail MX 5 shmail.abc.com 
10 shmail2.abc.com 
C. Sendmail finally requests dns to give the record of shmail.abc.com, that is, IP address. If the returned value is 1.2.3.4 
D. Sendmail connects to 1.2.3.4 and sends the mail to the SMTP backend of the server 1.2.3.4 to the shuser@sh.abc.com.Program  

7. SMTP basic command set: 

Command description 
------------------------------ 
Helo identifies a user to the server 
The sender can cheat and lie, but generally the server can detect it. 

Mail initialization Email transmission  
Mail from:  
RCPT identifies a single email recipient, often behind the MAIL command  
Multiple rcpt:  
After one or more RCPT commands, data indicates that all Email recipients have been identified, and data transmission is initiated to end.  
VRFY is used to verify whether the specified user or email address exists. This command is often disabled by the server for security reasons.  
EXPN verifies whether the specified mailbox list exists and expands the mailbox list.  
Help query commands supported by the server  
No Noop operation, the server should respond OK  
Quit end session  
Rset resets the session and the current transmission is canceled.  
--------------------------------  

8. the address specified in the mail from command is called envelope from address. It does not need to be the same as the sender's own address. 
Rcpt to is equivalent to the following: the specified receiver address is called envelope to address, but it has nothing to do with the actual to: What is the row. 
9. Why is there no RCPT cc or rcpt bcc :? 
All receiver negotiation is implemented through the rcpt to command. If it is Bcc, the recipient of the envelope is deleted after the negotiation is sent and received by the recipient. 
10. emails are divided into envelope, header, and body. 
Envelope from, envelope to and message from:, Message to: are completely irrelevant. 
Evnelope is provided by the SMTP backend between server hosts, while message from/to is provided by users. It is also different if there is a colon. 

11. How can I check whether a letter is forged in the envelope part?  
A. correlated ed rows are correlated.  
In the current SMTP mail Transmission System, apart from the internal hosts at both ends of the envelope, consider the two company firewalls.  
If the two firewall machines are A and B respectively, but the receiver checks the envelope written ed: when the line is found to have passed C. It is forged.  
B. Received: whether the host and IP address pairs in the row correspond:  
Receibed: From galangal.org (turmeric.com [104.128.23.115] by mail .bieberdorf.edu ....  
C. Manually added to the final stored row:  
Received: From galangal.org ([104.128.23.115]) by mail .bieberdorf.edu (8.8.8.5)  
Received: From lemongrass.org by galangal.org (8.7.3)  
Received: From graprao.com by lemongrass.org (8.6.4)  

From: http://blue.bsdbase.com/freebsd_bbs/viewtopic.php? T = 45

Gadfly Reply: 10:00:45

I just want to tell you this.ArticleThis is a perfect solution for your convenience. 
From http://www.longen.org/S-Z/details ~ Z/smtppipelineextension.htm 

SMTP service extension of Command Flow 

1. Summary 

This article mainly defines an SMTP service extension. Using this service extension server, you can describe how many commands it can receive in a TCP sending operation. Using multiple operations in a TCP sending command can greatly improve the system running efficiency. 

2. Introduction 

Although the SMTP service has been widely used and the effect is good, its extension is also indispensable. If a network needs to be connected for a long time, SMTP runs poorly. The time for SMTP is charged for waiting for commands one by one. If you enable the SMTP client to run commands, that is, to send multiple commands at a time, the operation efficiency will be improved. However, this was not described in previous protocols, and the customer could not know how many commands the server could receive at the same time. As a result, the following problems occur: 

The connection is out of control or the buffer is full; 
When the SMTP command fails, clear the TCP input buffer, which is sometimes unnecessary; 
For some commands, it will be judged as a failure without reason. For example, some servers will not receive the data command after the previous rept to failure, regardless of whether the command before rcpt to is successful, some servers can receive data commands when the rcpt to Command fails. 
3. Command Flow extension framework 

It is defined as follows: 

The name of this service extension is pipeline ); 
The extended value associated with EHLO is pipelining; 
Pipelining EHLO is no longer a parameter; 
The mail from or rcpt to command does not include other parameters; 
No other SMTP commands are attached; 
4. Streamline service expansion 

When the client wants to use the stream, it will send the EHLO command to the server. If the server responds with 250 (The response includes pipelining), it indicates that the server supports the SMTP service flow. 

4.1. Customer usage 

When the customer knows that the server can support the flow of data, the customer can transmit multiple commands (called command groups) to the server, instead of sending one wait and then sending another one, special rset, mail from, send from, soml from, saml from, and rcpt to can appear anywhere in the Command Group. EHLO, Data, VRFY, EXPN, turn, quit, and Noop can only appear in the last position of the Command Group, because their success or failure changes the status of SMTP commands. Commands generated by other SMTP extensions can only appear at the last position in the group. The actually transmitted command can be the first command in the group. 

The customer SMTP must check the status related to the data in the group. If the receiving address of rcpt tp is not accepted, the client must check the data status. The client cannot assume that data fails because no rcpt to is successful. If the data command is correctly rejected, the client can issue rset. If the Data command is not correctly rejected, the client must issue a dot ). The status generated by the command must be the same as that when each command is issued separately, and Multiline response must be supported. The customer SMTP can choose to run in a non-blocking state. It can process the response immediately when it receives the response from the server. even if there is still data to be sent, the response cannot be postponed. If non-blocking is not supported, the client must check the size of the TCP window. The size of the TCP window must be greater than that of the Command Group. The window size is usually 4 kb. If such a check is not performed, it may lead to a deadlock.

4.2. server support for streamline 

The server should provide the following service extensions: 

 

the content of the TCP input buffer cannot be discarded under any circumstances;
When and only when one or more valid rcpt to commands are received,
because the data command does not have a valid receiver, when the result receives null information, do not send a message to anyone (of course, a response is required to the Data command );
grouping rset, mail from, send from, soml from, the responses of the saml from and Rcpt to commands are saved and sent together;
responses to EHLO, Data, VRFY, EXPN, turn, quit, and Noop cannot be cached;
responses to unrecognized commands cannot be buffered;
when the local TCP input buffer is empty, all unsent responses must be sent;
you are not allowed to speculate on commands that have not been received, or assume that they exist;
which command is returned when the table is displayed in the response text;
5. example

Below is an SMTP session that does not support the flow of data: S represents the server, and C represents the client; 

S: <waiting to open the connection>; 

C: <open connection>; 

S: 220 innosoft.com SMTP Service ready 

C: helo dbc. mtview. ca. US 

S: 250 innosoft.com 

C: mail from: <mrose@dbc.mtview.ca.us>; 

S: 250 sender <mrose@dbc.mtview.ca.us>; OK 

C: rcpt to: <ned@innosoft.com>; 

S: 250 recipient <ned@innosoft.com>; OK 

C: rcpt to: <dan@innosoft.com>; 

S: 250 recipient <dan@innosoft.com>; OK 

C: rcpt to: <kvc@innosoft.com>; 

S: 250 recipient <kvc@innosoft.com>; OK 
...

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.