Notifies MailBee to stop processing jobs, completing sending out of all messages currently being processed.
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 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 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 It’s not possible to use SendMailMerge method to resume the stopped mail-merge process. To resume the mail-merge processing initiated with SendMailMerge method, use SendJobs method.
| Exception Type | Condition |
|---|---|
| MailBeeInvalidStateException | The operation currently in progress is not processing jobs so it cannot be stopped with this method. |
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 If the application is made multi-threaded (MaxThreadCount is not 1), multiple threads will accessfailureCountvariable simultaneously. Thus, to keepfailureCountvalue accurate, the application must synchronize access to it. However, exact value offailureCountis 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.
[C#] 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:\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:\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); } }
[Visual Basic] Imports System Imports System.Data Imports System.Data.OleDb Imports MailBee Imports MailBee.Mime Imports MailBee.SmtpMail Class Sample ' Number of continuous failures (a series of failures occurring one-by-one). Shared failureCount As Integer = 0 ' If any e-mail succeeded, reset the counter. Shared Sub mailer_MessageSent(ByVal sender As Object, ByVal e As SmtpMessageSentEventArgs) failureCount = 0 Console.WriteLine("Message sent.") End Sub ' Increment the counter. Shared Sub mailer_MessageNotSent(ByVal sender As Object, ByVal e As SmtpMessageNotSentEventArgs) failureCount = failureCount + 1 Console.WriteLine("Message not sent.") If failureCount > 10 Then ' Tolerate no longer than 10 failures one-by-one. CType(sender, Smtp).StopJobs() Console.WriteLine("Too many messages not sent.") End If 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() ' 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. AddHandler mailer.MessageSent, AddressOf mailer_MessageSent AddHandler mailer.MessageNotSent, AddressOf 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). Dim connParams As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\Newsletter.mdb;" Dim table As DataTable = New DataTable ' 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 adapter.SelectCommand = command adapter.Fill(table) Finally If Not conn Is Nothing Then conn.Close() End If End Try ' Run mail merge. mailer.SendMailMerge(Nothing, Nothing, table) End Sub End Class
Smtp Class | MailBee.SmtpMail Namespace | StopJobsOnError | Abort