In previous section, I introduced how to use asynchronous mode. In this section, I will introduce how to send mass email with multiple threads in VB 6.0.
Visual Basic 6.0 doesn’t support multiple threads. However, FastSender object has an inner threading pool based on MaxThreads count. Firstly, Send method submits email to FastSender mail queue. Secondly threading pool retrieves email from mail queue and sends it out. Finally OnSent event informs that the email was sent successfully or unsuccessfully.
No. of worker threads in the threading pool of FastSender object is automatically adjusted based on the actual usage. The maximum no. of worker threads is up to the value of MaxThread property specified.
Note
Remarks: All of samples in this section are based on first section: Send email in a simple VB 6.0 project. To compile and run the following example codes successfully, please click here to learn how to create the test project and add reference of EASendMail to your project.
The following example codes demonstrate how to send mass email with multiple threads.
Note
To get the full sample projects, please refer to Samples section.
Option Explicit
Const ConnectNormal = 0
Const ConnectSSLAuto = 1
Const ConnectSTARTTLS = 2
Const ConnectDirectSSL = 3
Const ConnectTryTLS = 4
Private WithEvents m_oFastSender As EASendMailObjLib.FastSender
Private oSmtp As EASendMailObjLib.Mail
Private Sub Command1_Click()
Dim recipientAddr(3) As String
Dim i As Integer
If m_oFastSender Is Nothing Or oSmtp Is Nothing Then
Set m_oFastSender = New EASendMailObjLib.FastSender
Set oSmtp = New EASendMailObjLib.Mail
oSmtp.LicenseCode = "TryIt"
' Set the maximum no. of worker threads
m_oFastSender.MaxThreads = 10
End If
' Your sender email address
oSmtp.FromAddr = "test@emailarchitect.net"
' Your SMTP server address
oSmtp.ServerAddr = "smtp.emailarchitect.net"
' User and password for ESMTP authentication, if your server doesn't require
' User authentication, please remove the following codes.
oSmtp.UserName = "test@emailarchitect.net"
oSmtp.Password = "testpassword"
' ConnectTryTLS means if server supports SSL/TLS connection, SSL/TLS is used automatically
oSmtp.ConnectType = ConnectTryTLS
' If your server uses 587 port
' oSmtp.ServerPort = 587
' If your server uses 25/587/465 port with SSL/TLS
' oSmtp.ConnectType = ConnectSSLAuto
' oSmtp.ServerPort = 25 ' 25 or 587 or 465
recipientAddr(0) = "test@adminsystem.com"
recipientAddr(1) = "test1@adminsystem.com"
recipientAddr(2) = "test2@adminsystem.com"
For i = 0 To 2
oSmtp.ClearRecipient
oSmtp.AddRecipientEx recipientAddr(i), 0
oSmtp.Subject = "mass email test subject"
oSmtp.BodyText = "mass email test body sent from vb"
Call m_oFastSender.Send(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 & ": failed to send email: " & ErrDesc
End If
End Sub
Next Section
At next section I will introduce how to send email using EASendMail Service Queue in ASP.
Appendix
Comments
If you have any comments or questions about above example codes, please click here to add your comments.