SendByPickup Method


Submit email to threading-pool of FastSender object for sending email by IIS SMTP service pickup.

[Syntax]
Visual C++: HRESULT SendByPickup( BSTR PickupPath, IMail* pSmtp, long nKey,
                           BSTR tParam, long* pVal )
Visual Basic: SendByPickup( PickupPath As String, pSmtp As Object, nKey As Long, _
                           tParam As String ) As Long

Parameters

PickupPath
Pickup path of IIS SMTP Service.
pSmtp
IMail instance to send.
nKey
Any numeric value associated with current email.
tParam
Any string value associated with current email.

Return Value

If this method succeeds, the return value is zero; otherwise, the return value is non-zero.

Remarks

This method submits an email to threading-pool of FastSender object. Once this email is saved to pickup directory by FastSender, OnSent event will occur.

How does FastSender work?

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.

We strongly recommend you use EASendMail Service to send bulk emails instead of IIS SMTP service. To learn more detail, please have a look at: Work with EASendMail Service(Mail Queuing).

Examples

To get the full samples of EASendMail FastSender, please refer to Samples section.

[VB6, VBA - Send Mass Email with Multiple Threads - IIS SMTP]

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 m_oSmtp As EASendMailObjLib.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 EASendMailObjLib.FastSender
    Set m_oSmtp = New EASendMailObjLib.Mail
    ' for evaluation usage, please use "TryIt" as the license code.
    m_oSmtp.LicenseCode = "TryIt"    

    m_oFastSender.MaxThreads = 10 'set the maximum no. of worker threads
  End If
  
  Dim pickupPath  As String
  pickupPath = "C:\Inetpub\mailroot\Pickup"
        
  m_oSmtp.FromAddr = "test@emailarchitect.net"

  recipientAddr(0) = "test@adminsystem.com"
  recipientAddr(1) = "test1@adminsystem.com"
  recipientAddr(2) = "test2@adminsystem.com"
  
  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.SendByPickup(pickupPath, 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

From above code, you will find that FastSender only handles the email sending, you have to use Mail object to set subject, body text and etc... Then Send method passes Mail object to FastSender, FastSender will get the encoded content from Mail object and send it out. Therefore, if you want to change the email content dynamically for each email, you just need to change the properties of Mail object before invoking Send method.

  For i = 0 To 2
    m_oSmtp.ClearRecipient
    m_oSmtp.AddRecipient recipientAddr(i), recipientAddr(i), 0
    m_oSmtp.Subject = "test subject"
    'change body text for each email.
    m_oSmtp.BodyText = "Dear" & recipientAddr(i) & "test body" 
    Call m_oFastSender.SendByPickup( pickupPath, m_oSmtp, i, "any" )
  Next

Online Tutorials

Send Bulk Email with Multiple Threads in Visual C++
Send Bulk Email with Multiple Threads in VB6
Send Bulk Email with Multiple Threads in Delphi

See Also

Send Method
Programming with FastSender
Work with EASendMail Service(Mail Queuing)