Introduction to the SMTP protocol

Source: Internet
Author: User
Tags contains mail connect return unique id client

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 Winsockterminal 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 "ConnectTo ..." 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.ruSendmail8.6.12/8.6.9readyatWed,22Apr199822:54:41+0300
   220ESMTPspokenhere

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.

  HELOoleg

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 Mailfrom 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.

  MAILFROM:oleg@vbip.com

After the command is sent, if the server returns a 250 response to the code, you can send the Rcptto 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.

  RCPTTO:somebody@domain.com

If you want to send the message to multiple recipients. You need to use the Rcptto 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:Myfirste-mailmessage.
   Firstlineofamessage.
    Secondline.
    .

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. Once the server receives this flag, it will immediately return a response with a code of 250 and a unique ID number for the message.

  250WAA10568Messageacceptedfordelivery

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.

  QUIT
  221ns.cinfo.ruclosingconnection


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.