MailBee.NET Objects 4.0

Smtp.SubmitJobsToPickupFolder Method 

Saves all e-mails in the pending jobs queue (including e-mails generated via mail merge) as files in the pickup folder of MailBee Message Queue or IIS SMTP service.

public bool SubmitJobsToPickupFolder(
   string pickupFolderName
);

Parameters

pickupFolderName
The full physical path to MailBee Message Queue or IIS SMTP pickup folder (such as "C:\Inetpub\mailroot\Pickup").

Return Value

true, if the entire queue of pending jobs had been processed and saved; false, if the operation was stopped due to an error.

Remarks

This method can be used to submit jobs directly to MailBee Message Queue or IIS SMTP service bypassing SMTP protocol. This greatly improves performance of sending large volumes of jobs when MailBee Message Queue or IIS SMTP server is installed on the same machine or in the same LAN as the computer running MailBee. This method neither creates nor requires network connection.

Note   Although this method saves messages into files rather than sends them out, most methods and properties affecting SendJobs method execution (such as StopJobs or StopJobsOnError) apply to SubmitJobsToPickupFolder method as well. The same applies to processing of job queues (such as JobsPending).
In the case if messages are saved to pickup folder rather than being sent out, it's recommended to set StopJobsOnError to true. This is because if any error occurs during saving files (for instance, disk is full), most probably this error will repeat for all subsequent messages and it doesn't make sense to continue processing.

Exceptions

Exception Type Condition
MailBeeException An error occurred and ThrowExceptions is true.

Example

This console sample performs mail merge via submitting resulting messages into IIS SMTP pickup folder. Events are used to track progress of the operation.

[C#]
using System;
using System.Data;
using System.Data.OleDb;
using MailBee;
using MailBee.Mime;
using MailBee.SmtpMail;

class Sample
{
    static void mailer_MergingMessage(object sender, SmtpMergingMessageEventArgs e)
    {
        Console.WriteLine("Will create an e-mail from data row #" + e.MergeRowIndex);
    }

    static void mailer_SubmittingMessageToPickupFolder(object sender,
        SmtpSubmittingMessageToPickupFolderEventArgs e)
    {
        Console.WriteLine("Will queue an e-mail from data row #" + e.MergeRowIndex);
    }

    static void mailer_MessageSubmittedToPickupFolder(object sender,
        SmtpMessageSubmittedToPickupFolderEventArgs e)
    {
        Console.WriteLine("The e-mail from data row #" + e.MergeRowIndex +
            " saved as " + e.Filename);
    }

    static void Main(string[] args)
    {
        Smtp mailer = new Smtp();

        // Logging into a file is useful for troubleshooting.
        mailer.Log.Filename = @"C:\log.txt";
        mailer.Log.Enabled = true;
        mailer.Log.Format = LogFormatOptions.AddContextInfo;
        mailer.Log.Clear();

        // Subscribe to 3 events to track send bulk mail progress.
        mailer.MergingMessage += new SmtpMergingMessageEventHandler(mailer_MergingMessage);
        mailer.SubmittingMessageToPickupFolder +=
            new SmtpSubmittingMessageToPickupFolderEventHandler(
            mailer_SubmittingMessageToPickupFolder
            );
        mailer.MessageSubmittedToPickupFolder +=
            new SmtpMessageSubmittedToPickupFolderEventHandler(
            mailer_MessageSubmittedToPickupFolder
            );

        // Setup e-mail message header template for mail merge.
        mailer.Message.From.AsString = "John Doe <john.doe@domain.com>";
        mailer.Message.To.AsString = "##Name## <##Email##>";
        mailer.Message.Subject = "Our Jan/2007 newsletter";

        // Setup HTML body template.
        mailer.Message.BodyHtmlText = "<html>##Body##</html>";

        // Specify database connection string (it may be different in your case).
        string connParams = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Newsletter.mdb;";

        // Connect to the database and populate mail merge job to-do list with
        // the data from "mailing_list" table.
        using (OleDbConnection conn = new OleDbConnection(connParams))
        {
            // Open the connection and get the data.
            OleDbCommand command = new OleDbCommand("SELECT * FROM mailing_list", conn);
            conn.Open();
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            DataTable table = new DataTable();
            adapter.SelectCommand = command;
            adapter.Fill(table);

            mailer.AddJob(null, null, null, table);
        }

        // Run mail merge.
        mailer.SubmitJobsToPickupFolder(@"C:\Inetpub\mailroot\Pickup");
    }
}
[Visual Basic]
Imports System
Imports System.Data
Imports System.Data.OleDb
Imports MailBee
Imports MailBee.Mime
Imports MailBee.SmtpMail

Class Sample
    Shared Sub mailer_MergingMessage(ByVal sender As Object, ByVal e As SmtpMergingMessageEventArgs)
        Console.WriteLine("Will create an e-mail from data row #" & e.MergeRowIndex)
    End Sub

    Shared Sub mailer_SubmittingMessageToPickupFolder(ByVal sender As Object, _
            ByVal e As SmtpSubmittingMessageToPickupFolderEventArgs)
        Console.WriteLine("Will queue an e-mail from data row #" & e.MergeRowIndex)
    End Sub

    Shared Sub mailer_MessageSubmittedToPickupFolder(ByVal sender As Object, _
             ByVal e As SmtpMessageSubmittedToPickupFolderEventArgs)
        Console.WriteLine("The e-mail from data row #" & e.MergeRowIndex & " saved as " & e.Filename)
    End Sub

    Shared Sub Main(ByVal args() As String)
        Dim mailer As Smtp = New Smtp

        ' Logging into a file is useful for troubleshooting.
        mailer.Log.Filename = "C:\log.txt"
        mailer.Log.Enabled = True
        mailer.Log.Format = LogFormatOptions.AddContextInfo
        mailer.Log.Clear()

        ' Subscribe to 3 events to track send bulk mail progress.
        AddHandler mailer.MergingMessage, AddressOf mailer_MergingMessage
        AddHandler mailer.SubmittingMessageToPickupFolder, AddressOf mailer_SubmittingMessageToPickupFolder
        AddHandler mailer.MessageSubmittedToPickupFolder, AddressOf mailer_MessageSubmittedToPickupFolder

        ' Setup e-mail message header template for mail merge.
        mailer.Message.From.AsString = "John Doe <john.doe@domain.com>"
        mailer.Message.To.AsString = "##Name## <##Email##>"
        mailer.Message.Subject = "Our Jan/2007 newsletter"

        ' Setup HTML body template.
        mailer.Message.BodyHtmlText = "<html>##Body##</html>"

        ' Specify database connection string (it may be different in your case).
        Dim connParams As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Newsletter.mdb;"

        ' Connect to the database and populate mail merge job to-do list with
        ' the data from "mailing_list" table.
        Dim conn As OleDbConnection
        Try
            conn = New OleDbConnection(connParams)

            ' Open the connection and get the data.
            Dim command As OleDbCommand = New OleDbCommand("SELECT * FROM mailing_list", conn)
            conn.Open()
            Dim adapter As OleDbDataAdapter = New OleDbDataAdapter
            Dim table As DataTable = New DataTable
            adapter.SelectCommand = command
            adapter.Fill(table)

            mailer.AddJob(Nothing, Nothing, Nothing, table)
        Finally
            If Not conn Is Nothing Then
                conn.Close()
            End If

        End Try

        ' Run mail merge.
        mailer.SubmitJobsToPickupFolder("C:\Inetpub\mailroot\Pickup")
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace