Connecting to SMTP Server

Connecting to Server via Proxy Server

Sometimes we use proxy servers for communicating with the outside world. In such cases, mail clients are not able to communicate over the Internet without specifying the proxy address. Aspose.Email provides support for versions 4, 4a and 5 of SOCKS proxy protocol. This article provides a working sample of sending email using a proxy mail server. To send an email via a proxy server:

  1. Initialize SocksProxy with the required information, that is proxy address, port, and SOCKS version.
  2. Initialize SmtpClient with the host address, user name and password, and any other settings.
  3. Set the client’s SocksProxy property to the SocksProxy object created earlier.

The following code snippet shows you how to connect to a server via a proxy server.

Connecting to SMTP Server via HTTP Proxy Server

Aspose.Email lets you connect to the SMTP server via HTTP Proxy as shown in the following code sample.

Binding SMTP Client to Specific IP Address on Host

The possibility of a host having multiple ports available for sending out emails cannot be ruled out. In such cases, the requirement may arise to bind the email sending client to a specific port on the host for sending out emails. This can be achieved with Aspose.Email APIs as well using the SmtpClient.bindIPEndPoint property.

The API’s SmtpClient can be set to use a specific IP address on the host by specifying the specific IP Endpoint. The following code sample can be used to achieve this.