The following vb.net example codes demonstrate how to send email over TLS on 25 or 587 SMTP port.
SSL and TLS
SSL connection encrypts data between the SMTP component and SMTP server to protects user, password and email content in TCP/IP level. Now this technology is commonly used and many SMTP servers are deployed with SSL such as Gmail, Yahoo and Hotmail. There are two ways to deploy SSL on SMTP server:
Explicit SSL (TLS)
Using STARTTLS command to switch SSL channel on normal SMTP port (25 or 587);
Deploying SSL on another port (465 or other port, you may query it from your server administrator
TLS is the successor of SSL, EASendMail supports SSL 3.0/TLS1.0 - 1.2 very well. In EASendMail, ConnectSTARTTLS doesn’t mean TLS encryption, it means STARTTLS command in SMTP protocol.
You don’t have to set any property to enable TLS 1.2 encryption. If your server requires TLS 1.2 encryption, TLS 1.2 encryption is used automatically.
To enable TLS 1.2 on some legacy systems, you have to install required update/packages:
Before you can use the following codes, please download EASendMail SMTP Component and install it on your machine at first. Full sample proejcts are included in this installer.
Install from NuGet
You can also install the run-time assembly by NuGet. Run the following command in the NuGet Package Manager Console:
If you install it by NuGet, no sample projects are installed, only .NET assembly is installed.
To use EASendMail SMTP Component in your project, the first step is
of EASendMail to your project. Please create or open your project with Visual Studio,
then go to
Add Reference ->
Browse..., and select
Installation Path\Lib\net[version]\EASendMail.dll from your disk, click
OK, the reference of EASendMail
will be added to your project, and you can start to use it to send email
in your project.
Because EASendMail has separate builds for .Net Framework, please refer to the following table and choose the correct dll.
Separate builds of run-time assembly for .NET Framework 1.1, 2.0, 3.5, 4.0, 4.5, 4.6.1, .NET Core 2.1 and .NET Compact Framework 2.0, 3.5.
|File||.NET Framework Version|
Built with .NET Framework 1.1
It requires .NET Framework 1.1, 2.0, 3.5 or later version.
Built with .NET Framework 2.0
It requires .NET Framework 2.0, 3.5 or later version.
Built with .NET Framework 3.5
It requires .NET Framework 3.5 or later version.
Built with .NET Framework 4.0
It requires .NET Framework 4.0 or later version.
Built with .NET Framework 4.5
It requires .NET Framework 4.5 or later version.
Built with .NET Framework 4.6.1
It requires .NET Framework 4.6.1 or later version.
Built with .NET Core 2.1
It requires .NET Core 2.1 or later version.
Built with .NET Compact Framework 2.0
It requires .NET Compact Framework 2.0, 3.5 or later version.
Built with .NET Compact Framework 3.5
It requires .NET Compact Framework 3.5 or later version.
The following example codes demonstrate how to send email over TLS connection on 25 or 587 port.
In order to run it correctly, please change
recipient value to yours.
To get full sample projects, please download and install EASendMail on your machine.
' Add EASendMail namespace Imports EASendMail Module Module1 Sub Main() Try Dim oMail As New SmtpMail("TryIt") ' Set sender email address, please change it to yours oMail.From = "email@example.com" ' Set recipient email address, please change it to yours oMail.To = "firstname.lastname@example.org" ' Set email subject oMail.Subject = "test email from VB.NET project over TLS 25" ' Set email body oMail.TextBody = "this is a test email sent from VB.NET project, do not reply" ' Your SMTP server address Dim oServer As New SmtpServer("smtp.emailarchitect.net") ' User and password for ESMTP authentication, if your server doesn't require ' User authentication, please remove the following codes. oServer.User = "email@example.com" oServer.Password = "testpassword" ' Set 25 or 587 SMTP Port oServer.Port = 25 ' Detect TLS connection automatically oServer.ConnectType = SmtpConnectType.ConnectSSLAuto Console.WriteLine("start to send email ...") Dim oSmtp As New SmtpClient() oSmtp.SendMail(oServer, oMail) Console.WriteLine("email was sent successfully!") Catch ep As Exception Console.WriteLine("failed to send email with the following error:") Console.WriteLine(ep.Message) End Try End Sub End Module