Work with EASendMail Service (Email Queuing)


EASendMail Service is a light, fast email delivery service which works with EASendMail SMTP .Net Component and ANSMTP SMTP Component. It enables your application to send mass emails in background service. And it also supports picking the recipients from database in background and sending email in specified datetime. It saves a lot of time in developing application especially in newsletters application. We highly recommend that you use the EASendMail Service with your ASP.NET/Web Application.

To work with EASendMail Service, you should download EASendMail Service and install it on the server at first. If you are using a web hosting and you don't have permission to install service on the server, then EASendMail service is not suitable for you.

For common newsletter application, the body text ususally begins with "Dear [name] ... To unsuscribe the newsletter, please ... [email address]". To approach this body text, the 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 detail about the variables in EASendMail service, please click here.

Example

[ASP/VBScript] The following example demonstrates how to send email with ANSMTP SMTP Component. To get the full samples of EASendMail, please refer to Samples section.

[ASP]
Sub SendMail()
    Dim oSmtp
    Set oSmtp = Server.CreateObject("AOSMTP.Mail")
    'oSmtp.RegisterKey = "Your license code"
    
    oSmtp.Charset = "iso-8859-1" 
    
    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}"

    ''Attachs 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

No matter how many recipients (even thousands of email addresses) you specify in above sample, EASendMail SMTP Component uses very short time to submit the email to EASendMail Service, and EASendMail service will delivery the emails in background. The {$var_rcptname} and {$var_rcptaddr} will be replaced by the service automatically.

Another common situation is: most newsletter applications get the recipient name and address from database. To simplify the task of developer, EASendMail service 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.

Sub SendMail()
    Dim oSmtp
    Set oSmtp = Server.CreateObject("AOSMTP.Mail")
    'oSmtp.RegisterKey = "Your license code"
    
    oSmtp.Charset = "iso-8859-1"
    
    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())
    
    '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}"
    
    ' For more connection string
    ' MS SQL server
    '"Driver={SQL Server};Server=localhost;Database=pubs;Uid=sa;Pwd=asdasd;" 
    ' MS Access
    '"Driver={Microsoft Access Driver (*.mdb)};Dbq=C:\mydatabase.mdb;Uid=Admin;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;" 
    ' other connection string
    ' please refer to: http://www.connectionstrings.com/
    
    ' To check the database error, please use EASendMail Service Manager->Journal->System Error
    
    oSmtp.AddHeader "X-Data-Connection", "Driver={Microsoft Access Driver (*.mdb)};Dbq={$var_easendmailpath}\easendmail_demo.mdb;Uid=;Pwd=;"
    oSmtp.AddHeader "X-Sql-Select", "SELECT id, name, address FROM Recipients" 
    oSmtp.AddHeader "X-Sql-OnSentSuccess", "INSERT INTO sentlog ( server, email ) VALUES( '{$var_server}', '{$var_rcptaddr}' )"
    oSmtp.AddHeader "X-Sql-OnSentError", "INSERT INTO errorlog( email, server, errorcode, errordescription ) VALUES( '{$var_rcptaddr}', '{$var_server}', '{$var_errcode}', '{$var_errdesc}' )"
    
    'Attachs 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!" 'Get last error description 
    End If
End Sub  

To learn more detail about EASendMail Service, please refer to EASendMail Service.