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]
Private Sub SendEmail()
  Dim oSmtp As EASendMailObjLib.Mail
  Set oSmtp = New EASendMailObjLib.Mail
 
  oSmtp.LicenseCode = "TryIt"
  oSmtp.ServerAddr = "mail.adminsystem.com"
  oSmtp.FromAddr = "test@adminsystem.com"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.com", 0
 
  oSmtp.UserName = "test@adminsystem.com"
  oSmtp.Password = "test"
  
  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]
  Dim oSmtp
  Set oSmtp = Server.CreateObject("EASendMailObj.Mail")
 
  oSmtp.LicenseCode = "TryIt"
  oSmtp.ServerAddr = "mail.adminsystem.com"
  oSmtp.FromAddr = "test@adminsystem.com"
  oSmtp.AddRecipient "Support Team", "support@adminsystem.com", 0
 
  oSmtp.UserName = "test@adminsystem.com"
  oSmtp.Password = "test"
  
  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 <comdef.h>
#include <iostream>
 
#include "easendmailobj.tlh"
using namespace EASendMailObjLib;
using namespace std;
 
void SendEmail()
{
  ::CoInitialize( NULL );
  IMailPtr oSmtp = NULL;
  oSmtp.CreateInstance(__uuidof(EASendMailObjLib::Mail));
  oSmtp->LicenseCode = _T("TryIt");
	
  oSmtp->ServerAddr = _T( "mail.adminsystem.com" );
  oSmtp->FromAddr = _T( "test@adminsystem.com" );
  oSmtp->AddRecipient( _T("Support Team"), 
                          _T("support@adminsystem.com"), 0 );
 
  oSmtp->UserName = _T("test@adminsystem.com");
  oSmtp->Password = _T("test");
  
  oSmtp->BodyText = _T("Hello, this is a test....");
  if( oSmtp->SendMail() == 0 )
    cout << "Message delivered!" << endl;
  else
    cout << (const TCHAR*)(oSmtp->GetLastErrDescription()) << endl;
}

[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;

var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  oSmtp : TMail;
begin
  oSmtp := TMail.Create(Application);
  oSmtp.LicenseCode := 'TryIt';

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

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

  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.SSL_starttls property.

Example

[VB, VBA - Send Email over TLS]    
'Connect server over TLS by STARTTLS command
Dim oSmtp As EASendMailObjLib.Mail
Set oSmtp = new EASendMailObjLib.Mail 

oSmtp.LicenseCode = "TryIt" 

oSmtp.ServerAddr = "mail.adminsystem.com" 

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

' Enable TLS Connection
oSmtp.SSL_init
oSmtp.SSL_starttls = 1
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
 
oSmtp.SSL_uninit
 
[VB, VBA - Send Email over SSL]
'Connect server over SSL by direct SSL
Dim oSmtp As EASendMailObjLib.Mail
Set oSmtp = new EASendMailObjLib.Mail 
oSmtp.LicenseCode = "TryIt" 
 
oSmtp.ServerAddr = "mail.adminsystem.com"

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

' Enable SSL Connection
oSmtp.SSL_init
oSmtp.SSL_starttls = 0
'SMTP server usually uses 465 as the alone SSL port
oSmtp.ServerPort = 465 

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
 
oSmtp.SSL_uninit


[VBScript, ASP - Send Email over TLS]    
'Connect server over TLS by STARTTLS command
Dim oSmtp
Set oSmtp = Server.CreateObject("EASendMailObj.Mail") 

oSmtp.LicenseCode = "TryIt" 

oSmtp.ServerAddr = "mail.adminsystem.com" 

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

' Enable TLS Connection
oSmtp.SSL_init
oSmtp.SSL_starttls = 1
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
 
oSmtp.SSL_uninit
 
[VBScript, ASP - Send Email over SSL]
'Connect server over SSL by direct SSL
Dim oSmtp
Set oSmtp = Server.CreateObject("EASendMailObj.Mail")
oSmtp.LicenseCode = "TryIt" 
 
oSmtp.ServerAddr = "mail.adminsystem.com"
' Set User Authentication
oSmtp.UserName = "test@adminsystem.com"
oSmtp.Password = "test"

' Enable SSL Connection
oSmtp.SSL_init
oSmtp.SSL_starttls = 0
'SMTP server usually uses 465 as the alone SSL port
oSmtp.ServerPort = 465 
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
 
oSmtp.SSL_uninit

[Visual C++ - Send Email over TLS]
#include "stdafx.h"
#include <comdef.h>
#include <iostream>

#include "easendmailobj.tlh"
using namespace EASendMailObjLib;

using namespace std;
 
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" );
  
  // Set user authentication
  oSmtp->UserName = _T("test@adminsystem.com"); 
  oSmtp->Password = _T("test");
  
  //Enable TLS connection
  oSmtp->SSL_init();
  oSmtp->SSL_starttls = 1;  
  
  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 )
    cout << _T("Message delivered!") << endl;
  else
    cout << (const TCHAR*)(oSmtp->GetLastErrDescription()) << endl;
}

[Visual C++ - Send Email over SSL]
#include "stdafx.h"
#include <comdef.h>
#include <iostream>

#include "easendmailobj.tlh"
using namespace EASendMailObjLib;

using namespace std;
 
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" );
  
  // Set user authentication
  oSmtp->UserName = _T("test@adminsystem.com"); 
  oSmtp->Password = _T("test");
  
  //Enable SSL connection
  oSmtp->SSL_init();
  oSmtp->SSL_starttls = 0; 
  oSmtp->ServerPort = 465;
  
  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 )
    cout << _T("Message delivered!") << endl;
  else
    cout << (const TCHAR*)(oSmtp->GetLastErrDescription()) << endl;
}

[Delphi - Send Email over TLS]
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;

var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  oSmtp : TMail;
begin
  oSmtp := TMail.Create(Application);
  oSmtp.LicenseCode := 'TryIt';

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

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

  // Enable TLS connection
  oSmtp.SSL_init();
  oSmtp.SSL_starttls := 1;  

  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]
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;

var
  Form1: TForm1;

implementation
{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
  oSmtp : TMail;
begin
  oSmtp := TMail.Create(Application);
  oSmtp.LicenseCode := 'TryIt';

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

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

  // Enable SSL connection
  oSmtp.SSL_init();
  oSmtp.SSL_starttls := 0; 
  oSmtp.ServerPort := 465;        

  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