SmtpStopJobs Method
Notifies MailBee to stop processing jobs, completing sending out of all messages currently being processed.

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax
public void StopJobs()
Exceptions
ExceptionCondition
MailBeeInvalidStateExceptionThe operation currently in progress is not processing jobs so it cannot be stopped with this method.
Remarks

This method can be used to suspend jobs processing, if desired. Once StopJobs method is called and sending of all e-mail messages currently being processed is completed, the sending operation stops.

This method can stop submitting e-mails to the pickup folder (initiated with SubmitJobsToPickupFolder(String, Boolean) method) as well as sending e-mails out.

Because this method does not stop jobs processing immediately but simply tells MailBee to do not process new e-mails, it may take some time to complete processing e-mails currently being sent. Thus, the component will still be busy (IsBusy is true) after this method completes. To stop processing jobs immediately, the developer should rather use Abort method.

To resume the stopped process, the developer should call the same method that was originally called to start the processing (for instance, SendJobs or SubmitJobsToPickupFolder(String, Boolean) method).

If you want to make jobs processing stop automatically whenever an error occurs (i.e. any e-mail could not be sent), set StopJobsOnError property to true before starting processing jobs.

Note Note
It's not possible to use SendMailMerge(String, EmailAddressCollection, DataTable) method to resume the stopped mail-merge process. To resume the mail-merge processing initiated with SendMailMerge(String, EmailAddressCollection, DataTable) method, use SendJobs method.
Examples
This console sample sends mail merge out, stopping the entire process if number of consecutive failures to send an e-mail exceeds 10. This allows the application to skip random errors of sending e-mails to specific e-mail addresses but stop processing in the case if the error becomes permanent. It's assumed that it's unusual to get 10 bad e-mail addresses one-by-one and such situation should be treated as possible failure of the mail server itself.
Note Note
If the application is made multi-threaded (MaxThreadCount is not 1), multiple threads will access failureCount variable simultaneously. Thus, to keep failureCount value accurate, the application must synchronize access to it. However, exact value of failureCount is not important in our case (even if synchronization issues made it evaluate to, let's say, 9 or 12 instead of 10) since we only need it to determine if it's big or not. It's no big difference if the application stopped after 9 or after 10 (or 12) consecutive failures.
using System;
using System.Data;
using System.Data.OleDb;
using MailBee;
using MailBee.Mime;
using MailBee.SmtpMail;

class Sample
{
    // Number of continuous failures (a series of failures occurring one-by-one).
    static int failureCount    = 0;

    // If any e-mail succeeded, reset the counter.
    static void mailer_MessageSent(object sender, SmtpMessageSentEventArgs e)
    {
        failureCount = 0;
        Console.WriteLine("Message sent.");
    }

    // Increment the counter.
    static void mailer_MessageNotSent(object sender, SmtpMessageNotSentEventArgs e)
    {
        failureCount++;
        Console.WriteLine("Message not sent.");

        if (failureCount > 10)
        {
            // Tolerate no longer than 10 failures one-by-one.
            ((Smtp)sender).StopJobs();
            Console.WriteLine("Too many messages not sent.");
        }
    }

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

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

        // Uncomment the line below to use unlimited number of worker threads (up to 60)
        // and increase performance. Note that not all SMTP servers support this.

        // mailer.MaxThreadCount = -1;

        // Subscribe to events to track send bulk mail progress.
        mailer.MessageSent += new SmtpMessageSentEventHandler(mailer_MessageSent);
        mailer.MessageNotSent += new SmtpMessageNotSentEventHandler(mailer_MessageNotSent);

        // Setup SMTP server parameters.
        mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret");

        // 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:\Temp\newsletter.mdb;";

        DataTable table = new DataTable();

        // 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();
            adapter.SelectCommand = command;
            adapter.Fill(table);
        }

        // Run mail merge.
        mailer.SendMailMerge(null, null, table);
    }
}
See Also