User Authentication and SSL Connection


"5xx relay denied" Error - 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 EASendMailObj 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 UserName and Password property of Mail Object, 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 Mail.AuthType property.

Example

[VB, VBA - SMTP User Authentication]

Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4

Private Sub SendEmail()
  Dim oSmtp As EASendMailObjLib.Mail
  Set oSmtp = New EASendMailObjLib.Mail

  oSmtp.LicenseCode = "TryIt"
  oSmtp.ServerAddr = "mail.adminsystem.com"
 
  oSmtp.UserName = "test@adminsystem.com"
  oSmtp.Password = "test"

  ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically
  oSmtp.ConnectType = ConnectTryTLS

  oSmtp.FromAddr = "test@adminsystem.com"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.com", 0

  oSmtp.BodyText = "Hello, this is a test...."

  If oSmtp.SendMail() = 0 Then
    MsgBox "Message delivered!"
  Else
    MsgBox oSmtp.GetLastErrDescription()
  End If

End Sub


[VBScript, ASP - SMTP User Authentication] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") oSmtp.LicenseCode = "TryIt" oSmtp.ServerAddr = "mail.adminsystem.com" oSmtp.UserName = "test@adminsystem.com" oSmtp.Password = "test" ' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp.ConnectType = ConnectTryTLS oSmtp.FromAddr = "test@adminsystem.com" oSmtp.AddRecipient "Support Team", "support@adminsystem.com", 0 oSmtp.BodyText = "Hello, this is a test...." If oSmtp.SendMail() = 0 Then Response.Write "Message delivered!" Else Response.Write oSmtp.GetLastErrDescription() End If
[Visual C++ - SMTP User Authentication] #include "stdafx.h" #include <tchar.h> #include <Windows.h> #include "easendmailobj.tlh" using namespace EASendMailObjLib; const int ConnectNormal = 0; const int ConnectSSLAuto = 1; const int ConnectSTARTTLS = 2; const int ConnectDirectSSL = 3; const int ConnectTryTLS = 4; void SendEmail() { ::CoInitialize(NULL); IMailPtr oSmtp = NULL; oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail)); oSmtp->LicenseCode = _T("TryIt"); oSmtp->ServerAddr = _T("mail.adminsystem.com"); oSmtp->UserName = _T("test@adminsystem.com"); oSmtp->Password = _T("test"); // ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp->ConnectType = ConnectTryTLS; oSmtp->FromAddr = _T("test@adminsystem.com"); oSmtp->AddRecipient(_T("Support Team"), _T("support@adminsystem.com"), 0); oSmtp->BodyText = _T("Hello, this is a test...."); if (oSmtp->SendMail() == 0) _tprintf(_T("Message delivered!")); else _tprintf((const TCHAR*)oSmtp->GetLastErrDescription()); }
[Delphi - SMTP User Authentication] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail unit type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const ConnectNormal = 0; ConnectSSLAuto = 1; ConnectSTARTTLS = 2; ConnectDirectSSL = 3; ConnectTryTLS = 4; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var oSmtp : TMail; begin oSmtp := TMail.Create(Application); oSmtp.LicenseCode := 'TryIt'; // Your SMTP server address oSmtp.ServerAddr := 'smtp.emailarchitect.net'; // User and password for ESMTP authentication, if your server doesn't require // user authentication, please remove the following codes oSmtp.UserName := 'test@emailarchitect.net'; oSmtp.Password := 'testpassword'; // ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically oSmtp.ConnectType := ConnectTryTLS; // Set your sender email address oSmtp.FromAddr := 'test@emailarchitect.net'; // Add recipient email address oSmtp.AddRecipientEx('support@emailarchitect.net', 0); // Set email subject oSmtp.Subject := 'simple email from Delphi project'; // Set email body oSmtp.BodyText := 'this is a test email sent from Delphi project, do not reply'; ShowMessage('start to send email ...'); if oSmtp.SendMail() = 0 then ShowMessage('email was sent successfully!') else ShowMessage('failed to send email with the following error: ' + oSmtp.GetLastErrDescription()); end; end.

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 Mail.ConnectType property.

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 Windows 2008/2008 R2/7, please install this update:
https://www.microsoft.com/security/blog/2017/07/20/tls-1-2-support-added-to-windows-server-2008/

Example

[VB, VBA - Send Email over TLS on 25/587 project]   

Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4

' Connect server over TLS by STARTTLS command on 25/587 port
Dim oSmtp As EASendMailObjLib.Mail
Set oSmtp = new EASendMailObjLib.Mail 

oSmtp.LicenseCode = "TryIt" 

oSmtp.ServerAddr = "mail.adminsystem.com" 
oSmtp.ServerPort = 25

' Enable SSL/TLS Connection
oSmtp.ConnectType = ConnectSSLAuto

' Set User Authentication
oSmtp.UserName = "test@adminsystem.com"
oSmtp.Password = "test"

oSmtp.Subject = "test for ssl"
oSmtp.BodyText = "test body"
  
oSmtp.FromAddr = "test@adminsystem.com"
oSmtp.AddRecipient "Support Team", "Support@adminsystem.com", 0 
  
If oSmtp.SendMail() = 0 Then
  MsgBox "Message delivered"
Else
  MsgBox oSmtp.GetLastErrDescription()
End If
  

[VB, VBA - Send Email over SSL on 465 port] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 ' Connect server over SSL by direct SSL on 465 port Dim oSmtp As EASendMailObjLib.Mail Set oSmtp = new EASendMailObjLib.Mail oSmtp.LicenseCode = "TryIt" oSmtp.ServerAddr = "mail.adminsystem.com" ' SMTP server usually uses 465 as the alone SSL port oSmtp.ServerPort = 465 ' Enable SSL/TLS Connection oSmtp.ConnectType = ConnectSSLAuto ' Set User Authentication oSmtp.UserName = "test@adminsystem.com" oSmtp.Password = "test" oSmtp.Subject = "test for ssl" oSmtp.BodyText = "test body" oSmtp.FromAddr = "test@adminsystem.com" oSmtp.AddRecipient "Support Team", "Support@adminsystem.com", 0 If oSmtp.SendMail() = 0 Then MsgBox "Message delivered" Else MsgBox oSmtp.GetLastErrDescription() End If
[VBScript, ASP - Send Email over TLS on 25/587 port] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 ' Connect server over TLS by STARTTLS command on 25 port Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") oSmtp.LicenseCode = "TryIt" oSmtp.ServerAddr = "mail.adminsystem.com" oSmtp.ServerPort = 25 ' Enable SSL/TLS Connection oSmtp.ConnectType = ConnectSSLAuto ' Set User Authentication oSmtp.UserName = "test@adminsystem.com" oSmtp.Password = "test" oSmtp.Subject = "test for ssl" oSmtp.BodyText = "test body" oSmtp.FromAddr = "test@adminsystem.com" oSmtp.AddRecipient "Support Team", "Support@adminsystem.com", 0 If oSmtp.SendMail() = 0 Then Response.Write "Message delivered" Else Response.Write oSmtp.GetLastErrDescription() End If
[VBScript, ASP - Send Email over SSL on 465 port] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 ' Connect server over SSL by direct SSL on 465 port Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") oSmtp.LicenseCode = "TryIt" oSmtp.ServerAddr = "mail.adminsystem.com" 'SMTP server usually uses 465 as the alone SSL port oSmtp.ServerPort = 465 ' Enable SSL/TLS Connection oSmtp.ConnectType = ConnectSSLAuto ' Set User Authentication oSmtp.UserName = "test@adminsystem.com" oSmtp.Password = "test" oSmtp.Subject = "test for ssl" oSmtp.BodyText = "test body" oSmtp.FromAddr = "test@adminsystem.com" oSmtp.AddRecipient "Support Team", "Support@adminsystem.com", 0 If oSmtp.SendMail() = 0 Then Response.Write "Message delivered" Else Response.Write oSmtp.GetLastErrDescription() End If
[Visual C++ - Send Email over TLS on 25/587 port] #include "stdafx.h" #include <tchar.h> #include <Windows.h> #include "EASendMailObj.tlh" using namespace EASendMailObjLib; const int ConnectNormal = 0; const int ConnectSSLAuto = 1; const int ConnectSTARTTLS = 2; const int ConnectDirectSSL = 3; const int ConnectTryTLS = 4; void SendEmail() { ::CoInitialize(NULL); IMailPtr oSmtp = NULL; oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail)); // The license code for EASendMail ActiveX Object, // for evaluation usage, please use "TryIt" as the license code. oSmtp->LicenseCode = _T("TryIt"); oSmtp->ServerAddr = _T("mail.adminsystem.com"); oSmtp->ServerPort = 25; // Enable SSL/TLS connection oSmtp->ConnectType = ConnectSSLAuto; // Set user authentication oSmtp->UserName = _T("test@adminsystem.com"); oSmtp->Password = _T("test"); oSmtp->FromAddr = _T("test@adminsystem.com"); oSmtp->AddRecipient(_T("Support Team"), _T("support@adminsystem.com"), 0); oSmtp->Subject = _T("Test"); oSmtp->BodyText = _T("Hello, this is a test email from VC++ ...."); if (oSmtp->SendMail() == 0) _tprintf(_T("Message delivered!")); else _tprintf((const TCHAR*)oSmtp->GetLastErrDescription()); }
[Visual C++ - Send Email over SSL on 465 port] #include "stdafx.h" #include <tchar.h> #include <Windows.h> #include "EASendMailObj.tlh" using namespace EASendMailObjLib; const int ConnectNormal = 0; const int ConnectSSLAuto = 1; const int ConnectSTARTTLS = 2; const int ConnectDirectSSL = 3; const int ConnectTryTLS = 4; void SendEmail() { ::CoInitialize(NULL); IMailPtr oSmtp = NULL; oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail)); // The license code for EASendMail ActiveX Object, // for evaluation usage, please use "TryIt" as the license code. oSmtp->LicenseCode = _T("TryIt"); oSmtp->ServerAddr = _T("mail.adminsystem.com"); oSmtp->ServerPort = 465; // Enable SSL/TLS connection oSmtp->ConnectType = ConnectSSLAuto; // Set user authentication oSmtp->UserName = _T("test@adminsystem.com"); oSmtp->Password = _T("test"); oSmtp->FromAddr = _T("test@adminsystem.com"); oSmtp->AddRecipient(_T("Support Team"), _T("support@adminsystem.com"), 0); oSmtp->Subject = _T("Test"); oSmtp->BodyText = _T("Hello, this is a test email from VC++ ...."); if (oSmtp->SendMail() == 0) _tprintf(_T("Message delivered!")); else _tprintf((const TCHAR*)oSmtp->GetLastErrDescription()); }
[Delphi - Send Email over TLS on 25/587 port] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail unit type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const ConnectNormal = 0; ConnectSSLAuto = 1; ConnectSTARTTLS = 2; ConnectDirectSSL = 3; ConnectTryTLS = 4; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var oSmtp : TMail; begin oSmtp := TMail.Create(Application); oSmtp.LicenseCode := 'TryIt'; // Your SMTP server address oSmtp.ServerAddr := 'smtp.emailarchitect.net'; oSmtp.ServerPort := 25; // Enable SSL/TLS connection oSmtp.ConnectType := ConnectSSLAuto; // User and password for ESMTP authentication, // If your server doesn't require user authentication, please remove the following codes oSmtp.UserName := 'test@emailarchitect.net'; oSmtp.Password := 'testpassword'; // Set your sender email address oSmtp.FromAddr := 'test@emailarchitect.net'; // Add recipient email address oSmtp.AddRecipientEx('support@emailarchitect.net', 0); // Set email subject oSmtp.Subject := 'simple email from Delphi project'; // Set email body oSmtp.BodyText := 'this is a test email sent from Delphi project, do not reply'; ShowMessage('start to send email ...'); if oSmtp.SendMail() = 0 then ShowMessage('email was sent successfully!') else ShowMessage('failed to send email with the following error: ' + oSmtp.GetLastErrDescription()); end; end.
[Delphi - Send Email over SSL on 465 port] unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, EASendMailObjLib_TLB; // add EASendMail unit type TForm1 = class(TForm) Button1: TButton; procedure Button1Click(Sender: TObject); private { Private declarations } public { Public declarations } end; const ConnectNormal = 0; ConnectSSLAuto = 1; ConnectSTARTTLS = 2; ConnectDirectSSL = 3; ConnectTryTLS = 4; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender: TObject); var oSmtp : TMail; begin oSmtp := TMail.Create(Application); oSmtp.LicenseCode := 'TryIt'; // Your SMTP server address oSmtp.ServerAddr := 'smtp.emailarchitect.net'; oSmtp.ServerPort := 465; // Enable SSL/TLS connection oSmtp.ConnectType := ConnectSSLAuto; // User and password for ESMTP authentication, // If your server doesn't require user authentication, please remove the following codes oSmtp.UserName := 'test@emailarchitect.net'; oSmtp.Password := 'testpassword'; // Set your sender email address oSmtp.FromAddr := 'test@emailarchitect.net'; // Add recipient email address oSmtp.AddRecipientEx('support@emailarchitect.net', 0); // Set email subject oSmtp.Subject := 'simple email from Delphi project'; // Set email body oSmtp.BodyText := 'this is a test email sent from Delphi project, do not reply'; ShowMessage('start to send email ...'); if oSmtp.SendMail() = 0 then ShowMessage('email was sent successfully!') else ShowMessage('failed to send email with the following error: ' + oSmtp.GetLastErrDescription()); end; end.

Online Examples

Send Email over SSL/TLS - VB6
Send Email over SSL/TLS - VC++
Send Email over SSL/TLS - Delphi

Online Tutorial

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

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

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

See Also

Using EASendMail ActiveX Object
Registration-free COM with Manifest File
From, ReplyTo, Sender and Return-Path
Digital Signature and Email Encryption - S/MIME
DomainKeys Signature and DKIM Signature
Send Email without SMTP server(DNS lookup)
Work with EASendMail Service(Mail Queuing)
Programming with Asynchronous Mode
Programming with FastSender
Mail vs. FastSender
Bulk Email Sender Guidelines
Process Bounced Email (Non-Delivery Report) and Email Tracking
Work with RTF and Word
EASendMail ActiveX Object References
EASendMail SMTP Component Samples