SmtpAddJob Method (String, MailMessage, String, EmailAddressCollection) |
Namespace: MailBee.SmtpMail
public void AddJob( string tag, MailMessage msg, string senderEmail, EmailAddressCollection recipients )
using System; using MailBee; using MailBee.Mime; 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:\Temp\log.txt"; mailer.Log.Enabled = true; mailer.Log.Clear(); mailer.SmtpServers.Add("mail.domain.com", "jdoe", "secret"); MailMessage msg = new MailMessage(); // Compose the message #1. msg.From.AsString = "John Doe <jdoe@domain.com>"; msg.To.AsString = "sales@company1.com, Bob <bob@company2.com>"; msg.Subject = "This is subject"; msg.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, msg, "bounce@domain.com", null); // Note that we do re-recreate a MailMessage object. This overload of AddJob actually places // msg itself into the job list, not its copy. For AddJob(string, string, EmailAddressCollection) // overload, that would be different (it makes a snapshot of what's currently in mailer.Message // and puts a copy of mailer.Message object into the job list, not mailer.Message object itself). msg = new MailMessage(); // Compose the message #2. msg.From.AsString = "John Doe <jdoe@domain.com>"; msg.To.AsString = "peter@company.com"; msg.Subject = "This is another subject"; msg.BodyPlainText = "This is another body text"; // Put the message #2 into the queue. mailer.AddJob(null, msg, 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"); } }