EASendMail Service is a light and fast email delivery service which works with EASendMail SMTP .Net Component / ANSMTP SMTP Component to enable your application to send mass emails in background service. Along with its ability to picking recipients from database in background and sending email in specified datetime, it eases your task in developing featured email application such as newsletter application. We strongly recommend you to use EASendMail Service with your ASP.NET/Web Application.
To work with EASendMail Service, please download EASendMail Service and install it on your server. If you are using web hosting service and you don't have permission to install service on that server, EASendMail service is not suitable for you.
In most newsletter application, body text usually begins with "Dear [name] ... To unsubscribe this newsletter, please ... [email address]". To approach this body text, email application has to send email to every recipient one by one. EASendMail service provides an advanced technology (variables replacing) to process those emails. To learn more about the variables in EASendMail service, please click here.
Example
[ASP/VBScript] The following example demonstrates how to send email with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.
[ASP, VBScript - Send Email to Queue] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Sub SendMail() Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") ' For evaluation usage, please use "TryIt" as the license code. oSmtp.LicenseCode = "TryIt" ' Your SMTP server address, if you don't set server, EASendMail service uses the server setting in EASendMail Service Manager. oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication oSmtp.UserName = "test@emailarchitect.net" oSmtp.Password = "testpassword" ' If server supports SSL/TLS connection, SSL/TLS is used automatically. oSmtp.ConnectType = ConnectTryTLS oSmtp.Charset = "utf-8" oSmtp.From = "Tester" oSmtp.FromAddr = "tester@adminsystem.com" Dim recipients ' separate multiple addresses with comman(,) recipients = "NickName <to@adminsystem.com>, to1@adminsystem.com, to2@adminsystem.com" ' if you want to EASendMail service send the email after 10 minutes, please use the following code. ' you can also cancel the scheduled task in EASendMail Service Manager->Queue Monitor->Scheduled Tasks ' oSmtp.Date = DateAdd("n", 10, Now()) oSmtp.AddRecipientEx recipients, 0 ' Normal recipient ' oSmtp.AddRecipient CCName, CCEmailAddress, 1 'CC ' oSmtp.AddRecipient BCCName, BCCEmailAddress, 2 'BCC ' To avoid too many email address in the To header, ' using the following code can only 'display the current recipient oSmtp.DisplayTo = "{$var_rcpt}" ' attaches file to this email ' oSmtp.AddAttachment "c:\test.txt" Dim subject, bodytext subject = "test subject" bodytext = "Dear {$var_rcptname}, your email address is {$var_rcptaddr}" oSmtp.Subject = subject oSmtp.BodyText = bodytext Dim hres hres = oSmtp.SendMailToQueue() If hres = 0 Then Response.Write "Message was sent to EASendMail service successfully!" Else Response.Write "Error code: " & hres & "Please make sure you installed EASendMail Service on the server!" 'Get last error description End If End Sub
Background SMTP Service
No matter how many recipients (even thousands of email addresses) you specify in above sample, EASendMail SMTP Component spends very short time to submit the email to EASendMail Service (you will be impressed by its performance), and the emails will be delivered in background. {$var_rcptname} and {$var_rcptaddr} will be replaced by the service automatically.
Database Integration
Another typical usage scenario is that most newsletter applications get recipient name and address from database. To simplify the task of developer, EASendMail provides a very powerful way to select recipients from database automatically.
Example
[ASP] The following sample demonstrates how to select recipient from database by EASendMail service. To get the full samples of EASendMail, please refer to Samples section.
[ASP, VBScript - Send Email to Queue with Database Pickup] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Sub SendMail() Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") ' for evaluation usage, please use "TryIt" as the license code. oSmtp.LicenseCode = "TryIt" ' Your SMTP server address, if you don't set server, EASendMail service uses the server setting in EASendMail Service Manager. oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication oSmtp.UserName = "test@emailarchitect.net" oSmtp.Password = "testpassword" ' If server supports SSL/TLS connection, SSL/TLS is used automatically. oSmtp.ConnectType = ConnectTryTLS oSmtp.Charset = "utf-8" oSmtp.From = "Tester" oSmtp.FromAddr = "tester@adminsystem.com" ' Using this email to be replied to another address ' oSmtp.ReplyTo = ReplyAddress ' if you want to EASendMail service send the email after 10 minutes, please use the following code. ' oSmtp.Date = DateAdd("n", 10, Now()) ' Set Database Connection oSmtp.AddHeader "X-Data-Connection", "Driver={Microsoft Access Driver (*.mdb)};Dbq={$var_easendmailpath}\easendmail_demo.mdb;Uid=;Pwd=;" ' For more connection string ' MS SQL Server 2000 '"Driver={SQL Server};Server=localhost;Database=pubs;Uid=sa;Pwd=asdasd;" ' MS SQL Server 2005 ' "Driver={SQL Server Native Client};Server=localhost;Database=pubs;Uid=sa;Pwd=asdasd;" ' MS SQL Server 2008 ' "Driver={SQL Server Native Client 10.0};Server=localhost;Database=myDataBase;Uid=myUsername;Pwd=myPassword;" ' MS SQL Server 2012 ' "Driver={SQL Server Native Client 11.0};Server=localhost;Database=myDataBase;Uid=myUsername;Pwd=myPassword;" ' MS Access ' "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;" ' "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Uid=;Pwd=;" ' ORACLE ' "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;" ' MySQL ' "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabase;USER=myUsername;PASSWORD=myPassword;OPTION=3;" ' "Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDatabase;User=myUsername;Password=myPassword;Option=3;" ' other connection string ' please refer to: http:'www.connectionstrings.com/ ' To check the database error, please use EASendMail Service Manager -> Journal -> System Error ' EASendMail uses the following connection to connect to the database, the syntax is same as ' ADO connection object. ' EASendMail will select the fields by the following sql statement ' before sending email, ' then pick the recipient address from specified field. oSmtp.AddHeader "X-Sql-Select", "SELECT id, name, address FROM Recipients" ' pick "name" field as the recipient name and "address" field as the recipient address. ' you can also use {$var_srecord:fieldname} to pick any field in X-Sql-Select statement ' and put it to subject, bodytext, then EASendMail will replace it automatially. oSmtp.DisplayTo = """{$var_srecord:name}"" <{$var_srecord:address}>" oSmtp.AddHeader "X-Rcpt-To", "{$var_srecord:address}" ' EASendMail service will execute the following sql statement on ' every email was sent successfully. oSmtp.AddHeader "X-Sql-OnSentSuccess", "INSERT INTO sentlog (server, email) VALUES( '{$var_server}', '{$var_rcptaddr}')" ' EASendMail service will execute the following sql statement on ' every email was unable to sent. oSmtp.AddHeader "X-Sql-OnSentError", "INSERT INTO errorlog (email, server, errorcode, errordescription) VALUES('{$var_rcptaddr}', '{$var_server}', '{$var_errcode}', '{$var_errdesc}')" ' attaches file to this email ' oSmtp.AddAttachment "c:\test.txt" Dim subject, bodytext subject = "test subject" bodytext = "Hi {$var_srecord:name}, " & Chr(13) & Chr(10) bodytext = bodytext & "this sample demonstrates how to send email in asp.net with EASendMail service." & Chr(13) & Chr(10) & Chr(13) & Chr(10) bodytext = bodytext & "From:Tester" & Chr(13) & Chr(10) bodytext = bodytext & "To:{$var_srecord:address}" & Chr(13) & Chr(10) & Chr(13) & Chr(10) bodytext = bodytext & "Your id in database is {$var_srecord:id}." & Chr(13) & Chr(10) oSmtp.Subject = subject oSmtp.BodyText = bodytext Dim hres hres = oSmtp.SendMailToQueue() If hres = 0 Then Response.Write "Message was sent to EASendMail service successfully!" Else Response.Write "Error code: " & hres & "Please make sure you installed EASendMail Service on the server!" End If End Sub
Work with Job
With EASendMail 7.1, you can define batch emails as a Job. If you defined a Job, you can manage the Job in EASendMail SMTP Service Manager->Queue Monitor->Jobs. You can also execute a SQL statement after a Job is completed.
[ASP, VBScript - Send Email to Queue with Database Pickup + Job] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Sub SendMail() Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") ' for evaluation usage, please use "TryIt" as the license code. oSmtp.LicenseCode = "TryIt" ' Your SMTP server address, if you don't set server, EASendMail service uses the server setting in EASendMail Service Manager. oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication oSmtp.UserName = "test@emailarchitect.net" oSmtp.Password = "testpassword" ' If server supports SSL/TLS connection, SSL/TLS is used automatically. oSmtp.ConnectType = ConnectTryTLS oSmtp.Charset = "utf-8" oSmtp.From = "Tester" oSmtp.FromAddr = "tester@adminsystem.com" ' set this email to be replied to another address ' oSmtp.ReplyTo = ReplyAddress ' if you want to EASendMail service send the email after 10 minutes, please use the following code. ' oSmtp.Date = DateAdd("n", 10, Now()) ' Set Database Connection oSmtp.AddHeader "X-Data-Connection", "Driver={Microsoft Access Driver (*.mdb)};Dbq={$var_easendmailpath}\easendmail_demo.mdb;Uid=;Pwd=;" ' For more connection string ' MS SQL Server 2000 ' "Driver={SQL Server};Server=localhost;Database=pubs;Uid=sa;Pwd=asdasd;" ' MS SQL Server 2005 ' "Driver={SQL Server Native Client};Server=localhost;Database=pubs;Uid=sa;Pwd=asdasd;" ' MS SQL Server 2008 ' "Driver={SQL Server Native Client 10.0};Server=localhost;Database=myDataBase;Uid=myUsername;Pwd=myPassword;" ' MS SQL Server 2012 ' "Driver={SQL Server Native Client 11.0};Server=localhost;Database=myDataBase;Uid=myUsername;Pwd=myPassword;" ' MS Access ' "Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;Pwd=;" ' "Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=C:\mydatabase.accdb;Uid=;Pwd=;" ' ORACLE ' "Driver={Microsoft ODBC for Oracle};Server=OracleServer.world;Uid=Username;Pwd=asdasd;" ' MySQL ' "DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=myDatabase;USER=myUsername;PASSWORD=myPassword;OPTION=3;" ' "Driver={MySQL ODBC 5.1 Driver};Server=myServerAddress;Database=myDatabase;User=myUsername;Password=myPassword;Option=3;" ' other connection string ' please refer to: http:'www.connectionstrings.com/ ' To check the database error, please use EASendMail Service Manager -> Journal -> System Error ' EASendMail uses the following connection to connect to the database, the syntax is same as ' ADO connection object. ' EASendMail will select the fields by the following sql statement ' before sending email, ' then pick the recipient address from specified field. oSmtp.AddHeader "X-Sql-Select", "SELECT id, name, address FROM Recipients" ' pick "name" field as the recipient name and "address" field as the recipient address. ' you can also use {$var_srecord:fieldname} to pick any field in X-Sql-Select statement ' and put it to subject, bodytext, then EASendMail will replace it automatially. oSmtp.DisplayTo = """{$var_srecord:name}"" <{$var_srecord:address}>" oSmtp.AddHeader "X-Rcpt-To", "{$var_srecord:address}" ' EASendMail service will execute the following sql statement on ' every email was sent successfully. oSmtp.AddHeader "X-Sql-OnSentSuccess", "INSERT INTO sentlog (server, email) VALUES('{$var_server}', '{$var_rcptaddr}')" ' EASendMail service will execute the following sql statement on ' every email was failed to sent. oSmtp.AddHeader "X-Sql-OnSentError", "INSERT INTO errorlog (email, server, errorcode, errordescription) VALUES('{$var_rcptaddr}', '{$var_server}', '{$var_errcode}', '{$var_errdesc}')" ' Define a Job, you can monitor the Job in EASendMail SMTP Service Manager -> Queue Monitor -> Jobs oSmtp.AddHeader "X-EAS-JobID", "MyJob1" ' After all emails were sent in this job, the following SQL statement will be executed. oSmtp.AddHeader "X-Sql-OnJobCompleted", "INSERT INTO joblog (jobid) VALUES('MyJob1')" ' attaches file to this email ' oSmtp.AddAttachment "c:\test.txt" Dim subject, bodytext subject = "test subject" bodytext = "Hi {$var_srecord:name}, " & Chr(13) & Chr(10) bodytext = bodytext & "this sample demonstrates how to send email in asp.net with EASendMail service." & Chr(13) & Chr(10) & Chr(13) & Chr(10) bodytext = bodytext & "From:Tester" & Chr(13) & Chr(10) bodytext = bodytext & "To:{$var_srecord:address}" & Chr(13) & Chr(10) & Chr(13) & Chr(10) bodytext = bodytext & "Your id in database is {$var_srecord:id}." & Chr(13) & Chr(10) oSmtp.Subject = subject oSmtp.BodyText = bodytext Dim hres hres = oSmtp.SendMailToQueue() If hres = 0 Then Response.Write "Message was sent to EASendMail service successfully!" Else Response.Write "Error code: " & hres & "Please make sure you installed EASendMail Service on the server!" End If End Sub
Database Error Journal
You can check the database and SQL statement error in Journal->System Error
Database Server Driver
In X-Data-Connection header, you should specify a database driver to connect database. You can open "Control Panel" -> "Administrative Tools" - > "ODBC Data Sources" - "Drivers" to check current installed database drivers.
Common SQL Driver Download
If SQL Server is installed on a remote server, and you don't have SQL driver installed on local machine, then you need to download and install corresponding driver on local machine.
MS Access Database Driver Download
Microsoft Access Database Engine 2010 Redistributable
Work with digital signed/encrypted email
Because EASendMail service will replace the {$var_xxxx} variable in mail body, if your email is digital signed, this feature will cause the digital signature not to be verified. With EASendMail 4.6 and EASendMail service 2.1, if your email is digital signed or encrypted, EASendMail service will not replace the {$var_xxx} variable in mail body. And with EASendMail 4.6 and EASendMail service 2.1, there is a new feature named "late sign".
Example
[Visual Basic] The following example demonstrates how to send email with EASendMail SMTP Component. To get the full samples of EASendMail, please refer to Samples section.
[VBScript, ASP - Email Queue with Digital Signature] Const ConnectNormal = 0 Const ConnectSSLAuto = 1 Const ConnectSTARTTLS = 2 Const ConnectDirectSSL = 3 Const ConnectTryTLS = 4 Sub SendMail() Dim oSmtp Set oSmtp = Server.CreateObject("EASendMailObj.Mail") ' for evaluation usage, please use "TryIt" as the license code. oSmtp.LicenseCode = "TryIt" ' Your SMTP server address, if you don't set server, EASendMail service uses the server setting in EASendMail Service Manager. oSmtp.ServerAddr = "smtp.emailarchitect.net" ' User and password for ESMTP authentication oSmtp.UserName = "test@emailarchitect.net" oSmtp.Password = "testpassword" ' If server supports SSL/TLS connection, SSL/TLS is used automatically. oSmtp.ConnectType = ConnectTryTLS oSmtp.Charset = "utf-8" oSmtp.From = "Tester" oSmtp.FromAddr = "tester@adminsystem.com" Dim recipients ' separate multiple addresses with comman(,) recipients = "NickName <to@adminsystem.com>, to1@adminsystem.com, to2@adminsystem.com" ' if you want to EASendMail service send the email after 10 minutes, please use the following code. ' oSmtp.Date = DateAdd("n", 10, Now()) oSmtp.AddRecipientEx recipients, 0 ' Normal recipient ' oSmtp.AddRecipient CCName, CCEmailAddress, 1 'CC ' oSmtp.AddRecipient BCCName, BCCEmailAddress, 2 'BCC ' To avoid too many email address in the To header, using the following code can only 'display the current recipient oSmtp.DisplayTo = "{$var_rcpt}" ' add a header named "x-signer-pfx" and the value format is ' [pfxfullpath]/[pfx password] then EASendMail service will replace {$var_xxx} variable ' at first, then sign the mail by the specified certificate oSmtp.AddHeader "X-Signer-PFX", "c:\cert\sender.pfx/pfxpassword" ' attaches file to this email ' oSmtp.AddAttachment "c:\test.txt" Dim subject, bodytext subject = "test subject" bodytext = "Dear {$var_rcptname}, your email address is {$var_rcptaddr}" oSmtp.Subject = subject oSmtp.BodyText = bodytext Dim hres hres = oSmtp.SendMailToQueue() If hres = 0 Then Response.Write "Message was sent to EASendMail service successfully!" Else Response.Write "Error code: " & hres & "Please make sure you installed EASendMail Service on the server!" 'Get last error description End If End Sub
Bounced Email and SMTP Transport Error
When you send email with EASendMail Service, there are two situations:
If you send email with specified SMTP server, you should catch the error between EASendMail Service and your SMTP server by X-Sql-OnSentError or X-File-OnSentError; you also need to catch the error between your SMTP server and recipient SMTP server by non-delivery report, please have a look at the following flow chart:
To parse non-delivery report, please have a look at Process Bounced Email (Non-Delivery Report) and Email Tracking.
If you send email directly, you just need to catch the error between EASendMail Service and your SMTP server by X-Sql-OnSentError or X-File-OnSentError. You don't have to enable Non-delivery Report in EASendMail Service. So sending email directly is recommended, but you should have a static internet IP address on your server, otherwise most emails will be rejected by recipient SMTP server due to anti-spam policy. Please have a look at the following flow chart:
To send email directly (simulating a SMTP server), please also have a look at Bulk Email Sender Guidelines.
In EASendMail Service, it also provides some advanced features just like: Traffic Control, Connection Limit, Delivery Retry. To learn more about EASendMail Service, please refer to EASendMail Service.
Send Email to Remote Queue
Online Tutorials
Send Email in MS SQL Server - Tutorial
Send Email with Queue in ASP.NET + C#
Send Bulk Emails with Database Queue in ASP.NET + C#
Send Email with Queue in ASP.NET + VB
Send Bulk Emails with Database Queue in ASP.NET + VB
Send Email with Queue in ASP + VBScript
Send Bulk Emails with Database Queue in ASP + VBScript
Online Examples
VB6 -
Email Queue with EASendMail Service
VB6 -
Email Queue with Database
VC++ -
Email Queue with EASendMail Service
VC++ -
Email Queue with Database
Delphi -
Email Queue with EASendMail Service
Delphi -
Email Queue with Database
See Also
Using EASendMail ActiveX Object
Registration-free COM with Manifest File
User Authentication and SSL Connection
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
Digital Signature and Email Encryption - S/MIME
DomainKeys Signature and DKIM Signature
Send Email without SMTP server(DNS lookup)
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