Using EASendMail SMTP Component


Add Reference of EASendMail SMTP Component to Visual Stuido.NET Project

To use EASendMail SMTP Component in your project, the first step is "Add reference of EASendMail to your project". Please create/open your project with Visual Studio.NET, then choose menu->"Project"->"Add Reference"->".NET"->"Browse...", and choose the "Installation Path\Lib\[netversion]\EASendMail.dll" from your disk, click "Open"->"OK", the reference of EASendMail will be added to your project, and you can start to use EASendMail SMTP Component in your project.

SMTP Component for VB, C#, ASP.NET, C++/CLI

Install from NuGet

You can also install the run-time assembly by NuGet. Run the following command in the NuGet Package Manager Console:

Install-Package EASendMail

Deploying EASendMail SMTP Component with Application

After compiling your project, a copy of EASendMail.dll will be generated by compiler in same folder of your application executable file. Packing all the *.dll and *.exe in the folder to installer is ok. As EASendMail is a pure .NET Component, it doesn't require "Regsvr32" (self-register) to register the dll.

Deploying EASendMail SMTP Component with ASP.NET/Web Application

The EASendMail.dll should be copied to [website root folder]\bin folder or [virtual directory root]\bin folder. If the project is created by Visual Studio.NET + FrontPage Extension directly, Visual Studio.NET will deploy EASendMail.dll automatically.

Seperate builds of run-time assembly for .NET Framework 1.1, 2.0, 3.5, 4.0, 4.5, 4.61, .NET Core 2.1 and .NET Compact Framework 2.0, 3.5.

File .NET Framework Version
Lib\net11\EASendMail.dll Built with .NET Framework 1.1
It requires .NET Framework 1.1, 2.0, 3.5 or later version.
Lib\net20\EASendMail.dll Built with .NET Framework 2.0
It requires .NET Framework 2.0, 3.5 or later version.
Lib\net35\EASendMail.dll Built with .NET Framework 3.5
It requires .NET Framework 3.5 or later version.
Lib\net40\EASendMail.dll Built with .NET Framework 4.0
It requires .NET Framework 4.0 or later version.
Lib\net45\EASendMail.dll Built with .NET Framework 4.5
It requires .NET Framework 4.5 or later version.
Lib\net461\EASendMail.dll Built with .NET Framework 4.6.1
It requires .NET Framework 4.6.1 or later version.
Lib\netcoreapp2.1\EASendMail.dll Built with .NET Core 2.1
It requires .NET Core 2.1 or later version.
Lib\net20-cf\EASendMail.dll Built with .NET Compact Framework 2.0
It requires .NET Compact Framework 2.0, 3.5 or later version.
Lib\net35-cf\EASendMail.dll Built with .NET Compact Framework 3.5
It requires .NET Compact Framework 3.5 or later version.

Run-time library for .NET Compact Framework 2.0, 3.5

To use EASendMail in .NET Compact Framework 2.0 or 3.5, you should use Lib\net20-cf\EASendMail.dll or Lib\net20-cf\EASendMail.dll in your project. And if SSL/TLS connection is used in .NET Compact Framework 2.0 or 3.5, you should also copy "SecurityInterface.dll" to the same folder of your application.

Note: CF version of EASendMail.dll does not support digital signature, message encryption, domainkeys/DKIM and direct sending email (DNS lookup).

Install EASendMail SMTP Component to Global Assembly Cache - SSIS

For SQL Server Integration Services (SSIS) or other .NET integrated script platform, it requires external DLL to be installed into .NET Global Assembly Cache. You can install EASendMail to Global Assembly Cache like this:

Mail Address Syntax

For single email address (From), the syntax can be ["][display name]["]<email address>.
For example, "Tester, T" <test@adminsystem.com>, Tester <test@adminsystem.com>, <test@adminsystem.com> or test@adminsystem.com.

For mulitple email address (To, CC, Bcc), the syntax can be [single email],[single email]... (,;\r\n) can be used to separate multiple email addresses.
For example: "Tester, T" <test1@adminsystem.com>, Tester2 <test2@adminsystem.com>, <test3@adminsystem.com>, test4@adminsystem.com

Server Address Syntax

The server syntax is [server ip or domain] [port]. SPACE is used to separate server address and port. If port is not specified, default port 25 will be used.
For example: localhost 25 or localhost.

Example

[Visual Basic, C#, C++, JScript.NET] The following example demonstrates how to send email with EASendMail SMTP Component, but it doesn't demonstrates the events usage. To get the full samples of EASendMail, please refer to Samples section.

[VB - Send Email Example]
Imports EASendMail

Public Sub SendMail( sFrom As String, _ 
    sTo As String, _ 
    sCc As String, _  
    sServer As String, _
    sUserName As String, _
    sPassword As String, _
    sSubject As String, _
    sBodyText As String, _
    bSSLConnection As Boolean )

    Dim oMail As SmtpMail = New SmtpMail("TryIt")
    Dim oSmtp As SmtpClient = New SmtpClient
    'To generate a log file for SMTP transaction, please use 
    'oSmtp.LogFileName = "c:\smtp.log"

    Dim errStr As String = ""

    Try
    'From is a MailAddress object, in c#, it supports implicit converting from string. 
         ' The syntax is like this: "test@adminsystem.com" or "Tester<test@adminsystem.com>"
         ' The example code without implicit converting 
         ' oMail.From = New MailAddress( "Tester", "test@adminsystem.com" ) 
         ' oMail.From = New MailAddress( "Tester<test@adminsystem.com>") 
         ' oMail.From = New MailAddress( "test@adminsystem.com" ) 
         ' To, Cc and Bcc is a AddressCollection object, in C#, it supports implicit converting from string. 
         ' multiple address are separated with (,;) 
         ' The syntax is like this: "test@adminsystem.com, test1@adminsystem.com" 
         ' The example code without implicit converting 
         ' oMail.To = New AddressCollection( "test1@adminsystem.com, test2@adminsystem.com" ) 
         ' oMail.To = New AddressCollection( "Tester1<test@adminsystem.com>, Tester2<test2@adminsystem.com>")
         ' You can add more recipient by Add method 
         ' oMail.To.Add( New MailAddress( "tester", "test@adminsystem.com"))
	   
        oMail.From = New MailAddress( sFrom )
        oMail.To = New AddressCollection(sTo)
        oMail.Cc = New AddressCollection(sCc)
        oMail.Subject = sSubject
        oMail.TextBody = sBodyText
    ' If the sBodyText contains the html tag, please use 
        ' oMail.HtmlBody = sBodyText 
        ' Add attachment 
        ' oMail.AddAttachment( "c:\test.gif" )
       
        Dim oServer As SmtpServer = New SmtpServer(sServer)
        
        If sUserName.Length > 0 And sPassword.Length > 0 Then
            oServer.User = sUserName
            oServer.Password = sPassword
        End If

        If (bSSLConnection) Then
            oServer.ConnectType = SmtpConnectType.ConnectSSLAuto
        End If

        oSmtp.SendMail(oServer, oMail)
        MessageBox.Show(String.Format("The message was sent to {0} successfully!", _
oSmtp.CurrentSmtpServer.Server))

    Catch exp As SmtpTerminatedException
        errStr = exp.Message
    Catch exp As SmtpServerException
        errStr = String.Format("Exception: Server Respond: {0}", exp.ErrorMessage)
    Catch exp As System.Net.Sockets.SocketException
        errStr = String.Format("Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.ComponentModel.Win32Exception
        errStr = String.Format("Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message)
    Catch exp As System.Exception
        errStr = String.Format("Exception: Common: {0}", exp.Message)
    End Try
    If errStr.Length > 0 Then
        MessageBox.Show(errStr)
    End If
End Sub

[C# - Send Email Example]
using System;
using System.Collections;
using EASendMail;

public void SendMail( string sFrom, 
    string sTo, 
    string sCc, 
    string sServer,
    string sUserName,
    string sPassword,
    string sSubject,
    string sBodyText,
    bool bSSLConnection )
{
    SmtpMail oMail = new SmtpMail("TryIt");
    SmtpClient oSmtp = new SmtpClient();
    // To generate a log file for SMTP transaction, please use 
    // oSmtp.LogFileName = "c:\\smtp.log";
    
    string err = "";
       
    try
    {
    //From is a MailAddress object, in c#, it supports implicit converting from string. 
         // The syntax is like this: "test@adminsystem.com" or "Tester<test@adminsystem.com>"
         // The example code without implicit converting 
         // oMail.From = new MailAddress( "Tester", "test@adminsystem.com" ); 
         // oMail.From = new MailAddress( "Tester<test@adminsystem.com>");
         // oMail.From = new MailAddress( "test@adminsystem.com" ); 
         // To, Cc and Bcc is a AddressCollection object, in C#, it supports implicit converting from string.
         // multiple address are separated with (,;) 
         // The syntax is like this: "test@adminsystem.com, test1@adminsystem.com" // The example code without implicit converting 
         // oMail.To = new AddressCollection( "test1@adminsystem.com, test2@adminsystem.com" ); 
         // oMail.To = new AddressCollection( "Tester1<test@adminsystem.com>, Tester2<test2@adminsystem.com>");
         // You can add more recipient by Add method 
         // oMail.To.Add( new MailAddress( "tester", "test@adminsystem.com"));
	   
        oMail.From = sFrom;
        oMail.To = sTo;
        oMail.Cc = sCc;
        oMail.Subject = sSubject;
        oMail.TextBody = sBodyText;
    //If the sBodyText contains the html tag, please use 
        // oMail.HtmlBody = sBodyText; 
        // Add attachment 
        // oMail.AddAttachment( "c:\\test.gif" );
        
        SmtpServer oServer = new SmtpServer( sServer );

        if( sUserName.Length != 0 && sPassword.Length != 0 )
        {
            oServer.User = sUserName;
            oServer.Password = sPassword;
        }
       
        if( bSSLConnection )
            oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;

        oSmtp.SendMail( oServer, oMail  );
        
        MessageBox.Show( String.Format( "The message was sent to {0} successfully!", 
            oSmtp.CurrentSmtpServer.Server ));

    }
    catch( SmtpTerminatedException exp )
    {
        err = exp.Message;
    }
    catch( SmtpServerException exp )
    {
        err = String.Format( "Exception: Server Respond: {0}", exp.ErrorMessage );
    }
    catch( System.Net.Sockets.SocketException exp )
    {
        err = String.Format( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
    }
    catch( System.ComponentModel.Win32Exception exp )
    {
        err = String.Format( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );          
    }
    catch( System.Exception exp )
    {
        err = String.Format( "Exception: Common: {0}", exp.Message );           
    }
    
    if( err.Length > 0  )
    {
        MessageBox.Show( err );
    }
}

[C++/CLI - Send Email Example]
using namespace System;
using namespace System::Collections;
using namespace EASendMail; 

System::Void SendMail( System::String ^sFrom, 
    System::String ^sTo, 
    System::String ^sCc, 
    System::String ^sServer,
    System::String ^sUserName,
    System::String ^sPassword,
    System::String ^sSubject,
    System::String ^sBodyText,
    bool bSSLConnection )
{
    SmtpMail ^oMail = gcnew SmtpMail("TryIt");
    SmtpClient ^oSmtp = gcnew SmtpClient();
    //To generate a log file for SMTP transaction, please use 
    //oSmtp->LogFileName = "c:\\smtp.log";

    System::String ^err = "";

    try
    {
    //From is a MailAddress object, in c#, it supports implicit converting from string. 
        //The syntax is like this: "test@adminsystem.com" or "Tester<test@adminsystem.com>"
        //The example code without implicit converting 
        // oMail->From = gcnew MailAddress("Tester", "test@adminsystem.com" ); 
        // oMail->From = gcnew MailAddress( "Tester<test@adminsystem.com>"); 
        // oMail->From = gcnew MailAddress( "test@adminsystem.com" ); 
        //To, Cc and Bcc is a AddressCollection object, in C#, it supports implicit converting from string.
        // multiple address are separated with (,;) 
        //The syntax is like this: "test@adminsystem.com, test1@adminsystem.com" 
        //The example code without implicit converting 
        // oMail->To  = gcnew AddressCollection( "test1@adminsystem.com, test2@adminsystem.com" ); 
        // oMail->To = gcnew AddressCollection( "Tester1<test@adminsystem.com>, Tester2<test2@adminsystem.com>");
        // You can add more recipient by Add method 
        // oMail->To->Add( gcnew MailAddress( "tester", "test@adminsystem.com")); 
	   
        oMail->From = gcnew EASendMail::MailAddress(sFrom);
        oMail->To =  gcnew EASendMail::AddressCollection(sTo);
        oMail->Cc = gcnew EASendMail::AddressCollection(sCc);
        oMail->Subject = sSubject;
        oMail->TextBody = sBodyText;
    //If the sBodyText contains the html tag, please use 
        //oMail->HtmlBody = sBodyText; 
        //Add attachment 
        //oMail->AddAttachment( "c:\\test.gif" );      
                
        SmtpServer ^oServer = gcnew SmtpServer( sServer );

        if( sUserName->Length != 0 && sPassword->Length != 0 )
        {
            oServer->User = sUserName;
            oServer->Password = sPassword;
        }

        if( bSSLConnection )
            oServer->ConnectType = SmtpConnectType::ConnectSSLAuto;

        oSmtp->SendMail( oServer, oMail );
    
        MessageBox::Show( String::Format( "The message was sent to {0} successfully!", 
            oSmtp->CurrentSmtpServer->Server ));

    }
    catch( EASendMail::SmtpTerminatedException ^exp )
    {
        err = exp->Message;
    }
    catch( EASendMail::SmtpServerException ^exp )
    {
        err = String::Format( "Exception: Server Respond: {0}", exp->ErrorMessage );
    }
    catch( System::Net::Sockets::SocketException ^exp )
    {
        err = String::Format( "Exception: Networking Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );
    }
    catch( System::ComponentModel::Win32Exception ^exp )
    {
        err = String::Format( "Exception: System Error: {0} {1}", exp->ErrorCode.ToString("d"), exp->Message );           
    }
    catch( System::Exception ^exp )
    {
        err = String::Format( "Exception: Common: {0}", exp->Message );            
    }
    
    if( err->Length > 0  )
    {
        MessageBox::Show( err );
    }
}

[JScript.NET - Send Email Example]
public function SendMail( sFrom:String, 
    sTo:String, 
    sCc:String, 
    sServer:String,
    sUserName:String,
    sPassword:String,
    sSubject:String,
    sBodyText:String,
    bSSLConnection:Boolean )
{
    var oMail:SmtpMail =  new SmtpMail("TryIt");
    var oSmtp:SmtpClient = new SmtpClient();
    //To generate a log file for SMTP transaction, please use 
    //oSmtp.LogFileName = "c:\\smtp.log";
        
    var err:String = "";    
    try
    {   
    //From is a MailAddress object, in c#, it supports implicit converting from string. 
        // The syntax is like this: "test@adminsystem.com" or "Tester<test@adminsystem.com>"
        // The example code without implicit converting 
        // oMail.From = new MailAddress( "Tester", "test@adminsystem.com" ); 
        // oMail.From = new MailAddress( "Tester<test@adminsystem.com>"); 
        // oMail.From = new MailAddress( "test@adminsystem.com" ); 
        // To, Cc and Bcc is a AddressCollection object, in C#, it supports implicit converting from string.
        // multiple address are separated with (,;) 
        //The syntax is like this: "test@adminsystem.com, test1@adminsystem.com" 
        //The example code without implicit converting 
        // oMail.To = new AddressCollection( "test1@adminsystem.com, test2@adminsystem.com" );
        // oMail.To = new AddressCollection( "Tester1<test@adminsystem.com>, Tester2<test2@adminsystem.com>");
        // You can add more recipient by Add method 
        // oMail.To.Add( new MailAddress( "tester","test@adminsystem.com"));
		    
        oMail.From  = new MailAddress(sFrom);
        oMail.Subject = sSubject
        oMail.To = new AddressCollection(sTo);
        oMail.Cc = new AddressCollection(sCc);
           
        oMail.TextBody = sBodyText;
    //If the sBodyText contains the html tag, please use 
        //oMail.HtmlBody = sBodyText; 
        //Add attachment 
        //oMail.AddAttachment( "c:\\test.gif" );               
        
        var oServer:SmtpServer = new SmtpServer(sServer);

        if( sUserName.Length != 0 && sPassword.Length != 0 )
        {
            oServer.User = sUserName;
            oServer.Password = sPassword;
        }

        if( bSSLConnection )
        {
            oServer.ConnectType = SmtpConnectType.ConnectSSLAuto;
        }

        oSmtp.SendMail( oServer, oMail );
        MessageBox.Show( String.Format("The message was sent to {0} successfully!", oServer.Server ));
        
    }
    catch( exp:SmtpTerminatedException  )
    {
        err = exp.Message;
    }
    catch( exp:SmtpServerException )
    {
        err = String.Format( "Exception: Server Respond: {0}", exp.ErrorMessage );
    }
    catch( exp:System.Net.Sockets.SocketException )
    {
        err = String.Format( "Exception: Networking Error: {0} {1}", exp.ErrorCode, exp.Message );
    }
    catch( exp:System.ComponentModel.Win32Exception )
    {
        err = String.Format( "Exception: System Error: {0} {1}", exp.ErrorCode, exp.Message );          
    }
    catch( exp:System.Exception )
    {
        err = String.Format( "Exception: Common: {0}", exp.Message );           
    }   
    
    if( err.Length > 0 )
    {
        MesageBox.Show( err );
    }
}

See Also

User Authentication and SSL Connection
From, ReplyTo, Sender and Return-Path
Digital Signature and E-mail Encryption
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

Online Tutorials

Send Email in VB 6.0 - Tutorial
Send Email in C# - Tutorial
Send Email in VB.NET - Tutorial
Send Email in Visual C++ - Tutorial
Send Email in Managed C++/CLI - Tutorial
Send Email in Delphi - Tutorial
Send Email in MS SQL stored procedure - Tutorial