User Authentication and SSL Connection


"5xx relay denied" SmtpServerException - you may have experienced this issue before when sending email with specified SMTP server. The following section explains why this happen and provide solutions.

When EASendMail sends email to SMTP server, SMTP server detects if the recipient is a local user (mailbox is on the current server). If it is not, SMTP server will relay it to the remote server. To stop daily increasing spam, most SMTP servers disable relaying email to remote server. That is why "5xx relay denied" occurs when you are sending email to a remote recipient via your SMTP server.

To enable local user to relay email to remote recipient, most SMTP servers provide ESMTP authentication. Once user authentication succeeded, SMTP server will relay email to any domain without limitation.

How to do ESMTP authentication?

You can simply assign your user name and password to User and Password property of SmtpServer class, EASendMail will then perform ESMTP authentication automatically before email is sent. The user name and password are usually same as your pop3 user name and password.

EASendMail supports most authentication mechanisms including: AUTH PLAIN, AUTH LOGIN, AUTH CRAM-MD5, AUTH NTLM, AUTH MSN. The authentication mechanism can either be detected by EASendMail automatically or specified by EASendMail.SmtpAuthType enumeration.

Example

[C# - User Authentication]
SmtpServer oServer = new SmtpServer("localhost");
oServer.AuthType = SmtpAuthType.AuthAuto;
oServer.User = "test@domain.com";
oServer.Password = "mypass";


[VB - User Authentication] Dim oServer As New SmtpServer("localhost") oServer.AuthType = SmtpAuthType.AuthAuto oServer.User = "test@domain.com" oServer.Password = "mypass"

SMTP SSL/TLS Connection

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. There are two ways to deploy SSL on SMTP server:

EASendMail SMTP component supports both ways. The connection can be specified by EASendMail.SmtpConnectType enumeration.

TLS 1.2 Encryption

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 with ConnectSSLAuto, ConnectSTARTTLS or ConnectDirectSSL.

To enable TLS 1.2 on some legacy systems, you have to install required update/packages:
Enable TLS 1.2 on Windows XP/2003/2008/7/2008 R2

Example

[C# - SSL/TLS]
// send email by normal TCP/IP without SSL connection
SmtpServer oServer = new SmtpServer("localhost 25");
oServer.ConnectType = SmtpConnectType.ConnectNormal;

// ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically
// If server doesn't support SSL/TLS, normal TCP is used
SmtpServer oServer = new SmtpServer("localhost 587");
oServer.ConnectType = SmtpConnectType.ConnectTryTLS;

// send email by SSL connection with STARTTLS command switching
SmtpServer oServer = new SmtpServer("localhost 25");
oServer.ConnectType = SmtpConnectType.ConnectSTARTTLS;

// send email by SSL connection with direct SSL.
SmtpServer oServer = new SmtpServer("localhost 465");
oServer.ConnectType = SmtpConnectType.ConnectDirectSSL;

// send email by SSL connection with auto-detect.
//if port is 25, STARTTLS SSL will be used; otherwise direct SSL will be used.
SmtpServer oServer = new SmtpServer("localhost 465");
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto 

SmtpServer oServer = new SmtpServer("localhost 25");
oServer.ConnectType = SmtpConnectType.ConnectSSLAuto 


[VB - SSL/TLS] ' Send email by normal TCP/IP without SSL connection Dim oServer As New SmtpServer("localhost 25") oServer.ConnectType = SmtpConnectType.ConnectNormal ' ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically ' If server doesn't support SSL/TLS, normal TCP is used Dim oServer As New SmtpServer("localhost 587") oServer.ConnectType = SmtpConnectType.ConnectTryTLS ' Send email by SSL connection with STARTTLS command switching Dim oServer As New SmtpServer("localhost 25") oServer.ConnectType = SmtpConnectType.ConnectSTARTTLS ' Send email by SSL connection with direct SSL. Dim oServer As New SmtpServer("localhost 465") oServer.ConnectType = SmtpConnectType.ConnectDirectSSL ' Send email by SSL connection with auto-detect. ' If port is 25 or 587, STARTTLS SSL will be used; otherwise direct SSL will be used. Dim oServer As New SmtpServer("localhost 465") oServer.ConnectType = SmtpConnectType.ConnectSSLAuto Dim oServer As New SmtpServer("localhost 25") oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
[C++/CLI - SSL/TLS] // Send email by normal TCP/IP without SSL connection SmtpServer^ oServer = gcnew SmtpServer("localhost 25"); oServer->ConnectType = SmtpConnectType::ConnectNormal; // ConnectTryTLS means if server supports SSL/TLS, SSL/TLS will be used automatically // If server doesn't support SSL/TLS, normal TCP is used SmtpServer^ oServer = gcnew SmtpServer("localhost 587"); oServer->ConnectType = SmtpConnectType::ConnectTryTLS; // Send email by SSL connection with STARTTLS command switching SmtpServer^ oServer = gcnew SmtpServer("localhost 25"); oServer->ConnectType = SmtpConnectType::ConnectSTARTTLS; // Send email by SSL connection with direct SSL. SmtpServer^ oServer = gcnew SmtpServer("localhost 465"); oServer->ConnectType = SmtpConnectType::ConnectDirectSSL; // Send email by SSL connection with auto-detect. // If port is 25 or 587, STARTTLS SSL will be used; otherwise direct SSL will be used. SmtpServer^ oServer = gcnew SmtpServer("localhost 465"); oServer->ConnectType = SmtpConnectType::ConnectSSLAuto SmtpServer^ oServer = gcnew SmtpServer("localhost 25"); oServer->ConnectType = SmtpConnectType::ConnectSSLAuto;

Online Examples

Send Email over SSL/TLS - C#
Send Email over SSL/TLS - Visual Basic
Send Email over SSL/TLS - C++/CLI

Online Tutorial

Send Email over SSL/TLS in C#
Send Email using Gmail in C#
Send Email using Yahoo in C#
Send Email using Hotmail/Live in C#

Send Email over SSL/TLS in VB
Send Email using Gmail in VB
Send Email using Yahoo in VB
Send Email using Hotmail/Live in VB

Send Email over SSL/TLS in C++/CLI
Send Email using Gmail in C++/CLI
Send Email using Yahoo in C++/CLI
Send Email using Hotmail/Live in C++/CLI

See Also

Using EASendMail SMTP .NET Component
Enable TLS 1.2 on Windows XP/2003/2008/7/2008 R2
Using Gmail SMTP OAUTH
Using Gmail/GSuite Service Account + SMTP OAUTH Authentication
Using Office365 EWS OAUTH
Using Office365 EWS OAUTH in Background Service
Using Hotmail SMTP OAUTH
From, ReplyTo, Sender and Return-Path
DomainKeys and DKIM Signature
Send E-mail Directly (Simulating SMTP server)
Work with EASendMail Service (Email Queuing)
Bulk Email Sender Guidelines
Process Bounced Email (Non-Delivery Report) and Email Tracking
EASendMail .NET Namespace References
EASendMail SMTP Component Samples