SMTP is used to deliver e-mail messages on the Internet. Document RFC821 provides all the details of the agreement. But you just have to remember the following-the basic commands and methods of the agreement.
The principle of the protocol is simple. Nothing more than a client computer sending a command to the server, and then the server returns some information to the client computer. The commands sent by the guest room and the server response are strings, and you don't need special software to read them. If you look closely at the source code of the Winsock Terminal sample program, you will find this out. Now let's use this sample program to send an email to ourselves.
Run the sample program, click the Connect button, enter the address of your e-mail server in the Connect to ... dialog box, and select the SMTP option. Finally press the "Connect" button. If the connection succeeds, the Winsock control generates a connected event, and information about the success of the connection is also visible in the status bar. In the main text window you will see the text returned from the server. The text contains a three-digit code and description, such as:
220-ns.cinfo.ru Sendmail 8.6.12/8.6.9 Ready at Wed, APR 1998 22:54:41 +0300
ESMTP spoken here
You don't have to be too careful about these descriptions. Because these descriptions may vary depending on the server. All you need to know is what the code means. Code 220 indicates that the connection was successfully established and the server waits for your first command.
The first command passed to the server is helo. The command contains a parameter, which is your mailbox name.
HELO Oleg
Note: In RFC821, Helo is an optional command that you can ignore if the server does not require the command.
If the command succeeds, the server returns a response with a code of 250. Next, use the mail from command to tell the server that you want to send an e-mail. The command takes the sender's e-mail address as a parameter.
MAIL from:oleg@vbip.com
After the command is sent, if the server returns a 250 response to the code, you can send the RCPT TO command to the server. This command takes the address of the addressee as a parameter, and it is known to tell the server that you want to send the message to the address of the addressee.
RCPT to:somebody@domain.com
If you want to send the message to multiple recipients. You need to use the RCPT TO command multiple times, and for each command, the server will return a response with a code of 250.
Now you can send the message body to the server. Use the data command to tell the server that the following content is the message body. After you receive a 354 response from the server, you can send the message body. Messages are sent by line, and each line of mail ends with a newline character that has no carriage return (vblf in VB) The sample program knows when to use a newline character and when to use a carriage return to add a newline character. So all you have to do is press ENTER. Here is an example:
Subject:my-E message.
A message.
Second line.
.
Note that the last character in the last line above is a decimal. This is the sign of the end of the text. Using VB code is VBLF & "." & VbCrLf. When the server receives this flag, it immediately returns you a response with a code of 250 and a unique ID number for the message.
WAA10568 message accepted for delivery
The task is complete, you can continue to send the next message, you can also disconnect from the server. Use the QUIT command if you want to disconnect from the server. In this case, the server returns a response with a code of 221 and disconnects.
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.