SmtpMaxThreadCount Property
Gets or sets the maximum number of threads MailBee may create during send mail operations.

Namespace: MailBee.SmtpMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 12.4 build 677 for .NET 4.5
public int MaxThreadCount { get; set; }

Property Value

Type: Int32
An integer value specifying the maximum number of threads MailBee may create during send mail operations, or -1 which specifies the number of threads is not limited. The default value is 1 (i.e. multi-threading is off).
MailBeeInvalidArgumentExceptionvalue is zero.
Multi-threading may greatly increase performance of send bulk mail (mail merge) and direct send operations (sending directly to recipients' SMTP servers through MX lookup). For instance, if the message is addressed to 5 recipients on the different domains (and therefore 5 SMTP connections must be made), the component can submit the message to all 5 SMTP servers simultaneously.
Caution note Caution
Some methods and properties of Smtp component cannot be used in multi-thread mode. For instance, if there are 3 simultaneous SMTP connections opened, it's not possible to determine for which SMTP connection GetServerResponse method should return the response. In multi-thread mode, the developer should use Smtp class events in order to track progress of operations. In multi-thread mode, IsSmtpContext always returns false.

The maximum number of threads MailBee can utilize is 60. Threads are taken from ThreadPool. In .NET Core and UWP, Tasks are used instead.

Note Note
If logging SMTP session into a file is enabled (Enabled property of Log object is true), it's recommended to include context information into the log when multi-thread mode is used. The developer can use AddContextInfo flag for this purpose. The sample code in the bottom of this page demonstrates how this option can be used. If context information was not added, the log file would be more difficult to read and analyze.

This sample sends message using MX lookup (no SMTP relay server is used), spawning as many threads as required (MaxThreadCount is -1). The message contains the following recipients:,,, Thus, the message must be sent to SMTP servers of 3 domains:,, Since the maximum number of threads is not limited, the component will create 3 threads in this case.

The MessageSubmittedToServer event is used to track submission of the message to each of 3 domains. If the message is successfully delivered to SMTP servers of all 3 domains, this event will occur 3 times total.

using System;
using MailBee;
using MailBee.SmtpMail;
using MailBee.Mime;

class Sample
    // MessageSubmittedToServer event handler.
    private static void OnMessageSubmittedToServer(
        object sender, SmtpMessageSubmittedToServerEventArgs e)
        // Show all recipients which were accepted by SMTP server. This event 
        // is raised for every recipient domain which accepted at least one 
        // recipient. As for the current sample, this event will occur 3 times 
        // if each domain's SMTP server accepted at least one recipient.
        foreach (EmailAddress address in e.AcceptedRecipients)
            Console.WriteLine("Message sent to " + address.Email);

    // The actual code.
    static void Main(string[] args)
        Smtp mailer = new Smtp();

        // Enable logging of send mail session into a file.
        // Context information will be added into the log as well.
        mailer.Log.Enabled = true;
        mailer.Log.Filename = @"C:\Temp\log.txt";
        mailer.Log.Format = LogFormatOptions.AddContextInfo;

        // Get DNS servers for MX lookup from the config file 
        // or operating system settings.

        // Set sender.
        mailer.From.AsString = "John Doe <>";

        // Set recipients (we specify multiple recipient domains 
        // to demonstrate effect of multi-threading).
        mailer.To.AsString = "C.J. Smith <>, " +
            "\"Kathy Long\" <>, " +
            "Bob <>,";

        // Set message body and subject.
        mailer.Subject = "Annual report";
        mailer.BodyHtmlText = "<html>That's it.</html>";

        // Allow MailBee to create as many threads as required 
        // to send mail to all recipient domains simultaneously.
        mailer.MaxThreadCount = -1;

        // Subscribe to the MessageSubmittedToServer event.
        mailer.MessageSubmittedToServer +=
            new SmtpMessageSubmittedToServerEventHandler(OnMessageSubmittedToServer);

        // Send it!
See Also