C #

Source: Internet
Author: User

C # Pop3 class:

We will design the C # Pop3 Class Based on this class. The C # Pop3 class contains the basic attributes, methods, and events required for email communication.

First, let's design the attributes. This class should include host name, port number, user name, password, mail quantity, total mail volume, mail content, status information, and other attributes. The first four attributes are readable and writable, and the last four attributes are only readable.

The specific settings are as follows:

 
 
  1. public string Host  
  2. {  
  3. get {return host;}  
  4. set  
  5. {  
  6. if(value == null || value.Trim().Length == 0)  

  • {
  • Throw new ArgumentException ("Invalid host name .");
  • }
  • Host = value;
  • }
  • }
  •  
  • ///
  • /// Port number
  • ///
  • Public int Port
  • {
  • Get {return port ;}
  • Set
  • {
  • If (value<= 0)
  • {
  • Throw new ArgumentException ("Invalid port .");
  • }
  • Port = value;
  • }
  • }
  •  
  • ///
  • /// User Name
  • ///
  • Public string UserName
  • {
  • Get {return username ;}
  • Set
  • {
  • If (value = null | value. Trim (). Length = 0)
  • {
  • Throw new ArgumentException ("Invalid user name .");
  • }
  • Username = value;
  • }
  • }
  •  
  • ///
  • /// Password
  • ///
  • Public string PassWord
  • {
  • Get {return password ;}
  • Set
  • {
  • If (value = NULL)
  • {
  • Throw new argumentexception ("invalid password .");
  • }
  • Password = value;
  • }
  • }
  •  
  • ///
  • /// Number of emails
  • ///
  • Public int numofmails
  • {
  • Get {return numofmails ;}
  • }
  •  
  • ///
  • /// Total mail volume
  • ///
  • Public double totalsize
  • {
  • Get {return totalsize ;}
  • }
  •  
  • ///
  • /// Email content
  • ///
  • Public string Body
  • {
  • Get {return body ;}
  • }
  •  
  • ///
  • /// Status information
  • ///
  • Public string Status
  • {
  • Get {return status ;}
  • }
  • After completing the attribute design of this class, we will complete the method design of this class. The main method of this class is ReceiveMessage (), which means to receive mail information. With this object, we can more easily perform network communication operations. However, before introducing the implementation of this method, I must first introduce the basic principles of mail receipt.

    The basic principles are as follows:

    At the beginning, it was the connection between the client and the server. However, before connecting the client to the server, set the port to the default port number 110 of POP3 protocol. After the client successfully connects to the server, the server returns the following information:

    + OK ......

    Character + OK is the return information of POP3 protocol. Unlike the SMTP protocol, its response information is represented by a variety of numbers, with only two: + OK or-ERR. + OK indicates that the connection is successful, and-ERR indicates that the connection fails. Next, enter USER <USER Name> on the client. This Command tells the server your USER name. Note that some servers are case-sensitive.

    After the server returns + OK, the client enters the PASS <password>

    After the server returns the + OK message, it also returns some mailbox statistics, such as: + OK 1 message (s) [1304 byte (s)] Different server return different formats, so we can use the STAT command to view the mailbox information. The STAT command responds with two numbers, indicating the number of mails and the size of mails, respectively. The C # Pop3 class is described above.

    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.