Using C # for SMTP protocol client development experience--connection

Source: Internet
Author: User
smtp| Client | Experience I. About connecting to the server

There are two general ways to connect with an SMTP server:

First type:
When the server address is a string type, such as "smtp.tom.com", "211.128.11.25", we can establish a connection with the TcpClient class.

TcpClient = new TcpClient (SmtpServer, Smtpport);

Subordinate namespaces:
System.Net.Sockets.TcpClient
In order for the TcpClient to connect and exchange data, the TcpListener or Socket created using TCP ProtocolType must listen for incoming connection requests. You can connect to the listener by using one of the following two methods:

Create a tcpclient and call one of the three available Connect methods.
Create a TcpClient using the host name and port number of the remote host. This constructor will automatically attempt a connection.


The second type:

When the server address is the form of an IP address, the IPEndPoint class is used to connect it.

IPEndPoint smtpserveripendpoint = new IPEndPoint (smtpserveripaddress,smtpport);

We can convert the server address of type string to the form of an IP address:

IPAddress hostipaddress = (Dns.resolve (hoststring)). ADDRESSLIST[0];

Subordinate namespaces: System.Net.EndPoint

The IPEndPoint class contains the host and port information required by the application to connect to the service on the host. By combining the host IP address and port number of the service,
The IPEndPoint class forms the connection point to the service.





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.