MailBee.NET Objects 4.0

Smtp.AddJob Method (String, String, EmailAddressCollection)

Puts an e-mail message onto waiting list for subsequent processing in bulk mode.

public void AddJob(
   string tag,
   string senderEmail,
   EmailAddressCollection recipients
);

Parameters

tag
Any string the developer wants to assign to Tag property of SendMailJob object created by this method. The developer can leave it a null reference (Nothing in Visual Basic).
senderEmail
The e-mail address of the sender. If it's a null reference (Nothing in Visual Basic), the e-mail address is taken from From property.
recipients
The list of the message recipients. If it's a null reference (Nothing in Visual Basic), the recipients list is combined from To, Cc, and Bcc lists.

Remarks

This method can be used to send out large volumes of messages (in conjunction with SendJobs method). The given overload composes a single e-mail message from the current values of Message and DeliveryNotification objects and then adds it as a job waiting for processing into JobsPending queue. Then, once SendJobs method has been called, MailBee starts processing all the jobs in this queue and sending out all the accompanied e-mails.

Alternatively, if SubmitJobsToPickupFolder has been called instead of SendJobs, the pending e-mails will be saved as .EML files in MailBee Message Queue or IIS pickup folder.

Note   Another AddJob overload can be used to enqueue a mail merge job of processing a bulk of similar messages based on a common template and a data table.

Example

This sample adds two e-mails into the jobs queue and then sends them in a batch.

[C#]
using System;
using MailBee;
using MailBee.SmtpMail;

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

        // Because SendJobs does not throw exceptions during sending of
        // individual messages, logging is very useful for debugging.
        mailer.Log.Filename = @"C:\log.txt";
        mailer.Log.Enabled = true;
        mailer.Log.Clear();

        mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret");

        // Compose the message #1.
        mailer.From.AsString = "John Doe <jdoe@domain.com>";
        mailer.To.AsString = "sales@company1.com, Bob <bob@company2.com>";
        mailer.Subject = "This is subject";
        mailer.BodyPlainText = "This is body text";

        // Put the message #1 into the queue. The message will actually be
        // sent from bounce@domain.com while jdoe@domain.com will appear
        // in "From:" header of the message.
        mailer.AddJob(null, "bounce@domain.com", null);

        // Compose the message #2.
        mailer.From.AsString = "John Doe <jdoe@domain.com>";
        mailer.To.AsString = "peter@company.com";
        mailer.Subject = "This is another subject";
        mailer.BodyPlainText = "This is another body text";

        // Put the message #2 into the queue.
        mailer.AddJob(null, null, null);

        // Send out the bulk of 2 messages.
        mailer.SendJobs();

        // Print the outcome.
        Console.WriteLine(mailer.JobsSuccessful.Count + " message(s) succeeded");
        Console.WriteLine(mailer.JobsFailed.Count + " message(s) failed");
    }
}
[Visual Basic]
Imports System
Imports MailBee
Imports MailBee.SmtpMail

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

        ' Because SendJobs does not throw exceptions during sending of
        ' individual messages, logging is very useful for debugging.
        mailer.Log.Filename = "C:\log.txt"
        mailer.Log.Enabled = True
        mailer.Log.Clear()

        mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret")

        ' Compose the message #1.
        mailer.From.AsString = "John Doe <jdoe@domain.com>"
        mailer.To.AsString = "sales@company1.com, Bob <bob@company2.com>"
        mailer.Subject = "This is subject"
        mailer.BodyPlainText = "This is body text"

        ' Put the message #1 into the queue. The message will actually be
        ' sent from bounce@domain.com while jdoe@domain.com will appear
        ' in "From:" header of the message.
        mailer.AddJob(Nothing, "bounce@domain.com", Nothing)

        ' Compose the message #2.
        mailer.From.AsString = "John Doe <jdoe@domain.com>"
        mailer.To.AsString = "peter@company.com"
        mailer.Subject = "This is another subject"
        mailer.BodyPlainText = "This is another body text"

        ' Put the message #2 into the queue.
        mailer.AddJob(Nothing, Nothing, Nothing)

        ' Send out the bulk of 2 messages.
        mailer.SendJobs()

        ' Print the outcome.
        Console.WriteLine(mailer.JobsSuccessful.Count & " message(s) succeeded")
        Console.WriteLine(mailer.JobsFailed.Count & " message(s) failed")
    End Sub
End Class

See Also

Smtp Class | MailBee.SmtpMail Namespace | Smtp.AddJob Overload List | SendJobs | SubmitJobsToPickupFolder