ANSMTP Developers Center > Threading-Pool in Visual Basic
Note: this article is only suitable for ANSMTP 6.4 or later.
For ANSMTP 6.3 or earlier version, please click here.
Introduction
To enhance the performance in sending mass mail, FastSender Object, which is designed based on multi-threading algorithm, is added to ANSMTP. This tutorial shows how to use FastSender in your application.
Send mass emails using FastSender.
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.
How does it work?
FastSender object provides an easy way to send mass emails with high performance.
FastSender has an inner threading pool based on MaxThreads count. Firstly, Send or SendByPickup submits email to FastSender mail queue. Secondly threading pool retrieves email from mail queue and send it out. Finally OnSent event informs that the email was sent successfully or unsuccessfully.
No. of worker threads in the threading pool of FastSender is automatically adjusted based on the actual usage. The maximum no. of worker threads is up to the value of MaxThread property specified.
Simple Sample
The following code demonstrates how to use FastSender object to send mass emails.
Option Explicit
Private WithEvents m_oFastSender As AOSMTPLib.FastSender
Private m_oSmtp As AOSMTPLib.Mail
Private Sub SendEmail()
Dim recipientAddr(3) As String
Dim i As Integer
If m_oFastSender Is Nothing Or m_oSmtp Is Nothing Then
Set m_oFastSender = New AOSMTPLib.FastSender
Set m_oSmtp = New AOSMTPLib.Mail
m_oFastSender.MaxThreads = 10 'set the maximum no. of worker threads
End If
m_oSmtp.FromAddr = "test@adminsystem.net"
m_oSmtp.ServerAddr = "mail.adminsystem.net"
'if you don't have a SMTP server, use the following code:
'FastSender sends email via DNS lookup
'm_oSmtp.ServerAddr = ""
recipientAddr(0) = "test@adminsystem.net"
recipientAddr(1) = "test1@adminsystem.net"
recipientAddr(2) = "test2@adminsystem.net"
For i = 0 To 2
m_oSmtp.ClearRecipient
m_oSmtp.AddRecipient recipientAddr(i), recipientAddr(i), 0
m_oSmtp.Subject = "test subject"
m_oSmtp.BodyText = "test body"
Call m_oFastSender.Send( m_oSmtp, i, "any" )
Next
End Sub
Private Sub m_oFastSender_OnSent(ByVal lRet As Long, _
ByVal ErrDesc As String, _
ByVal nKey As Long, _
ByVal tParam As String, _
ByVal Sender As String, _
ByVal Recipients As String)
If lRet = 0 Then
MsgBox nKey & " email was sent successfully"
Else
MsgBox nKey & ": " & ErrDesc
End If
End Sub
How many threads should I use?
Basically, there is no limitation for worker threads count of FastSender,
it depends on hardware of your machine. We'v tested it with more than 100 threads on Windows XP C800/256M.
Suggestion for worker threads count:
1.Send email via dnslookup 20-50 threads.
2.Send email via IIS SMTP Service 10 threads.
3.Send email via IIS SMTP Pickup 10 threads
A Total Sample
Please refer to VBMassMailer sample in ANSMTP installation package.
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.
|