Connect to SMTP Servers using C#

Simple Mail Transfer Protocol (SMTP) is the most commonly used email protocol that deals with sending email messages from client applications to the email server. In various cases, the email clients are implemented within .NET applications in order to send emails via SMTP. For such scenarios, this article covers how to connect to an SMTP server programmatically using C#. Furthermore, the code samples demonstrate how to send an email via SMTP client after connection establishment.

C# API to Connect SMTP Server

Aspose.Email for .NET is a C# API that is designed to create powerful email client applications. The API makes it possible to perform complex email operations quite easily within a few lines of code. Furthermore, it allows you to connect SMTP servers via SOCKS and HTTP proxy servers. You can either download the API’s DLL or install it using NuGet.

PM> Install-Package Aspose.Email

Connect to SMTP Server using C#

Before connecting to an SMTP server, you need to have the following things known.

  • Username
  • Password
  • Port

Once you have them, you can configure the SMTP client using the following steps.

The following code sample shows how to set up the API for an SMTP connection in C#.

Once you have configured the API, you can connect to an SMTP server using one of the following options.

Connect to SMTP via SOCKS Proxy Server in C#

Aspose.Email provides support for versions 4, 4a, and 5 of the SOCKS proxy protocol. The following are the steps to connect to an SMTP server via a SOCKS proxy server using Aspose.Email for .NET.

The following code sample shows how to connect to an SMTP server via SOCKS proxy using C#.

Connect to SMTP Server via HTTP Proxy Server

The following are the steps to connect to an SMTP server via an HTTP proxy server.

The following code sample shows how to connect to an SMTP server via HTTP proxy server.

Get a Free API License

You can try and use Aspose.Email for .NET for free by getting a temporary license.

Conclusion

In this article, you have learned how to connect to an SMTP server using C#. Furthermore, the step-by-step guide and code samples have shown how to connect to the SMTP server via SOCKS and HTTP proxy servers. You can explore more about the C# email API using documentation.

See Also