ANSMTP Developers Center > Email Queuing with Database
Note: this article is only suitable for ANSMTP 6.4 or later.
For ANSMTP 6.3 or earlier version, please click here.
Important notice: * We strongly recommand the developer use the ANSMTP 7.0 + EASendMail Service instead of database queuing.
Installation and Deployment
You should download the ansmtp installer and install it on your machine at first. If you want to distribute or deploy ansmtp without ansmtp installer, please click here to learn more.
Simple Email Queuing
SaveMailEx method of ANSMTP enables your application to send email by pickup path of IIS SMTP Service. All emails are queued and sent in background. Click here for more detail about IIS SMTP Service.
The following code demonstrates how to send email via IIS SMTP Service Queuing.
[ASP]
Dim oSmtp, pickupPath, arRecipients
Set oSmtp = Server.CreateObject("AOSMTP.Mail")
pickupPath = "c:\inetpub\mailroot\pickup"
arRecipients = Array( "test@adminsystem.net", _
"test1@adminsystem.net", _
"test2.adminsystem.net" )
oSmtp.FromAddr = "test@emailarchitect.net"
oSmtp.Subject = "test subject"
oSmtp.BodyText = "test body"
For i = 0 To 2
oSmtp.ClearRecipient
oSmtp.AddRecipient arRecipients(i), arRecipients(i), 0
If oSmtp.SaveMailEx( pickupPath ) = 0 Then
Response.Write "Email queued for " & arRecipients(i)
Else
Response.Write "SaveMailEx method failed for " & arRecipients(i)
End If
Next
If there are thousands of recipients, it will take a long time to run this .asp script. To save time, I'll introduce another solution, which is very suitable for newsletter applications.
Queuing with Database
Firstly, ASP/ASP.NET application collects the basic information including email subject, message body and SQL QUERY statement for selecting recipients from database. Secondly, those information will be inserted into a database table. Finally, the background application retrieves the record from this table and send all email in background.
Database Tables Introduction
EmailTask table; Recipients table;
The following code demonstrates how to submit a job to EmailTask table.
Sub Submit( subject, body, sqlRecipients )
Dim oConn, SQL
Set oConn = Server.Create("ADODB.Connection")
oConn.Open connStr
SQL="Insert into EmailTask ( subject, body, sqlRecipients ) " & _
values( '" & subject & "', '" & body & "','" & sqlRecipients & "')"
Conn.Execute SQL
End Sub
'Suppose that sqlRecipients = "select name, addr from Recipients",
'then the background application will send the email to all recipients
'queried by this SQL statement
'And no matter how many recipients are there,
'asp/asp.net inserts one record into database.
'therefore, it takes very short time to run this .asp
In fact, the above concept is useful to you to develop many other distribution systems.
Download a total sample for this article
This sample includes ASP/ASP.NET client and a Visual Basic background application. Access database is used in this sample, you can immigrate it to SQL server easily. You can even deploy client and background applications on different machines.
Note:* You should assign everyone read and write permission to EmailQueuing.mdb, otherwise an error "Microsoft JET Database Engine error '80004005', Operation must use an updateable query" raises.
Free Email Support
Not enough? Please contact our technical support team.
Support@EmailArchitect.NET
VIP@EmailArchitect.NET(Registered
User)
Remarks
We usually reply emails in 24hours. The reason for getting no response is
likely that your SMTP server bounced our reply. In this case, please try to use
another email address to contact us. Your Hotmail or Yahoo email account is
recommended.
|