SendByPickup Method

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

[Syntax]
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
C#: long SendByPickup( string PickupPath, MailClass pSmtp, long nKey, 
                           string tParam )

Parameter:

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 Values

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.

Usage Example:

[Visual Basic]
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
  Dim pickupPath  As String
  pickupPath = "C:\Inetpub\mailroot\Pickup"
  
  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 maximum work threads
  End If
  
  m_oSmtp.FromAddr = "test@adminsystem.net"
        
  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.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
[C#]
using System;
using AOSMTPLib;

namespace FastSenderConsole
{
  class FastSender
  {
    private static FastSenderClass m_oFastSender = null;
    private static MailClass m_oSmtp = null;

    [STAThread]
    static void Main(string[] args)
    {
      string []recipientAddr = new string[3];
      if( m_oFastSender == null ||  m_oSmtp == null )
      {
        m_oFastSender = new FastSenderClass();
        m_oSmtp = new MailClass();
        m_oFastSender.MaxThreads = 10; //set maximum work threads
        bind OnSent event to OnSent method
        _IFastSenderEvents_OnSentEventHandler OnSentEventHandler = 
                        new _IFastSenderEvents_OnSentEventHandler(OnSent);
        m_oFastSender.OnSent += OnSentEventHandler;
      }
      
      string pickupPath = "C:\\Inetpub\\mailroot\\Pickup";
      m_oSmtp.FromAddr = "test@adminsystem.net";
      
      recipientAddr[0] = "test@adminsystem.net";
      recipientAddr[1] = "test1@adminsystem.net";
      recipientAddr[2] = "test2@adminsystem.net";
      
      for( int i = 0; i < 3; i++ )
      {
        m_oSmtp.ClearRecipient();
        m_oSmtp.AddRecipient( recipientAddr[i], recipientAddr[i], 0 );
        m_oSmtp.Subject = "test subject";
        m_oSmtp.BodyText = "body";
        m_oFastSender.SendByPickup( pickupPath, m_oSmtp, i, "any" );
      }
      
      while( m_oFastSender.GetQueuedCount() > 0 )
        System.Threading.Thread.Sleep(50);
              
      while( m_oFastSender.GetCurrentThreads() != m_oFastSender.GetIdleThreads())
        System.Threading.Thread.Sleep(50); //Wait for all email sent
        
      Console.WriteLine( "all email sent" );
      System.Threading.Thread.Sleep(10000);
    }
    
    static void OnSent( int lRet, 
                        string ErrDesc, 
                        int  nKey, 
                        string tParam, 
                        string Sender, 
                        string Recipients )
    {
      if( lRet == 0 )
        Console.WriteLine("{0} email sent successfully", nKey);
      else
        Console.WriteLine( "{0} email: {1}", nKey, ErrDesc );
    }
  }
}

See Also

Send method


2001-2007 © Copyright AdminSystem Software Limited. All rights reserved.