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"

[JavaScript - User Authentication]
var oServer = new EASendMail.SmtpServer("localhost");
oServer.authType =  EASendMail.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.

Example

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

//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

' 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 

[JavaScript - SSL/TLS]
//send email by normal TCP/IP without SSL connection
var oServer = new EASendMail.SmtpServer("localhost 25");
oServer.connectType = EASendMail.SmtpConnectType.connectNormal;

//send email by SSL connection with STARTTLS command switching
var oServer = new EASendMail.SmtpServer("localhost 25");
oServer.connectType = EASendMail.SmtpConnectType.connectSTARTTLS;

//send email by SSL connection with direct SSL.
var oServer = new EASendMail.SmtpServer("localhost 465");
oServer.connectType = EASendMail.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.


var oServer = new EASendMail.SmtpServer("localhost 465");
oServer.connectType = EASendMail.SmtpConnectType.connectSSLAuto 

var oServer = new EASendMail.SmtpServer("localhost 25");
oServer.connectType = EASendMail.SmtpConnectType.connectSSLAuto 
		

Online Examples

Send Email over SSL - C#
Send Email over SSL - VB
Send Email over SSL - JavaScript

See Also

Using EASendMail SMTP Windows Runtime Component in Windows 8 Store App
EASendMail Windows 8 Runtime Component References
EASendMail SMTP Component Samples