SoFunction
Updated on 2025-04-09

How to send and receive emails under the command line (dos)

Today, I saw the introduction online that I used the command line to send and receive emails, so I wrote about the process in detail.
Receive email:
Open the Run dialog box in the Start menu and enter the command telnet and remote server port number, such as:
telnet pop3. 110  will establish a connection with the pop3 server pop3. of “NetEase 163 Free Mail”.
If the above connection is successful, the POP3 server will respond to the following information (displayed on the terminal):
+OK Welcome to coremail Mail Pop3 Server(163com[20050206])
user greenerycn If the username is logged in successfully, the POP3 server will respond to the following information:
+OK core mail 
Enter password Password If password is successful, the terminal will display the following information:
+OK 5 message (2267 octets) 
The number 5 indicates that there are 5 emails, and 2267 indicates the total number of bytes of these 5 emails (i.e. 2267B).
Then there are the following commands that can be used, and the command format and parameters are explained as follows:
Command Format: stat No parameters required
Command format: list [n] Article n is optional, n is the email number
Command format: uidl [n] Same as above
Command format: retr n parameter n cannot be saved, n is the email number
Command format: dele n Same as above
Command format: top n m parameter n, m cannot be saved, n is the email number, m is the number of rows
Command Format: noop No parameters required
Command Format: quit No parameters required
The detailed functions of each command are shown in the following description:
1. The stat command does not have parameters. For this command, the POP3 server will respond to a correct answer. This response is a single line of information prompts. It starts with "+OK", followed by two numbers. The first is the number of emails and the second is the size of the email, such as: +OK 4 1603
2. The parameter of the list command is optional. This parameter is a number, which represents the number of the email in the mailbox. We can use the list command without parameters to obtain the number of each email, and each email occupies a line to display. The number in front is the number of the email, and the number in the following is the size of the email.
3. The uidl command and list command are similar in purpose, except that the uidl command displays the information of the email more detailed and specific than the list, and the execution result is shown in Figure 4.
4. The retr command is the most important command in receiving emails. Its function is to view the content of the email. It must be performed with parameters. After the command is executed, the server responds to the information for a long time, including the sender's email address, sending time, email subject, etc. These information are collectively called the email header. The information immediately after the email header is the email text.
5. The dele command is used to delete the specified email (note: the dele n command only marks the email with a delete mark. The email will be deleted only after executing the quit command). The deleted response information is shown in Figure 6.
6. The top command has two parameters, such as: top n m n is the email number, m is the number of lines to read out the email text. If m=0, only the header of the email is read out.
7. Noop command. After the command is issued, the POP3 server does nothing and only returns a correct response "+OK"
8. quit command. After this command is issued, telnet disconnects the connection to the POP3 server and the system enters an update state. .
However, in this way, the emails you view are encoded and cannot be read in Chinese.
dos send a message
1. Calculate the base64 encoding of the user name and password: http://lishiditu./
[ telnet smtp. 25    //Login smtp. The port number is 25
220  Anti-spam GT for Coremail System (163com[20050206])
HELO localhost  //  Say hello to the server and tell the client the name of the machine you use. You can fill in it as you like
250 OK  
AUTH LOGIN     //Login command using identity authentication
334 dXNlcm5hbWU6  
YWJj //Enter the user name that has been base64_encode().
334 UGFzc3dvcm
MTIzNDU2//Enter the password that has been base64_encode()
235 Authentication successful
MAIL FROM:<greeenerycn@>  //Tell the address of the sender of the server
250 Mail OK
RCPT TO:<yourframe@> //Tell the address of the recipient of the server
250 Mail OK
DATA   //The content of the letter begins on the front and ends with a special line containing only  .
354 End data with <CR><LF>.<CR><LF>
To:yourframe@  
From:redsos3@
Subject:test mail
Test,# The content of the email text, start writing in one empty line with the header
test body
. # After writing the email, add a period to the carriage return result.
250 Mail OK queued as smtp14,F0CPBFsuzUOvoDwE.41582S2
QUIT//Disconnect
221 Bye
Connection closed by foreign host.
Status code description:
220: Service is ready
250: The request email action is correct and completed (HELO, MAIL FROM, RCPT TO, QUIT command execution will return this information)
235: Passed certification
221: Processing
354: Start sending data, end with. (This information will be returned after the execution of the DATA instruction)
500: Syntax error, command cannot be recognized
550: The command cannot be executed, the email address is invalid
552: Interrupt processing: User exceeds file space