SmtpAddJob Method (String, String, EmailAddressCollection, IDataReader) |
Puts a "mail merge over database" job onto waiting list for subsequent processing in bulk mode.
Namespace: MailBee.SmtpMailAssembly: MailBee.NET (in MailBee.NET.dll) Version: 12.5.0 build 687 for .NET 4.5
Syntax public void AddJob(
string tag,
string senderEmailPattern,
EmailAddressCollection recipientsPattern,
IDataReader mergeDataReader
)
Public Sub AddJob (
tag As String,
senderEmailPattern As String,
recipientsPattern As EmailAddressCollection,
mergeDataReader As IDataReader
)
Parameters
- tag
- Type: SystemString
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). - senderEmailPattern
- Type: SystemString
The e-mail address template of the sender. If it's a null reference
(Nothing in Visual Basic), the e-mail address template will be taken from From
property. - recipientsPattern
- Type: MailBee.MimeEmailAddressCollection
The e-mail address template of the recipients list. If it's a null reference
(Nothing in Visual Basic), the recipients list will be constructed via merge of To,
Cc, and Bcc patterns with actual values from the data source.
- mergeDataReader
- Type: System.DataIDataReader
The data source for mail merge, such as SqlDataReader.
Exceptions Remarks Examples using System;
using System.Data;
using System.Data.SqlClient;
using MailBee;
using MailBee.Mime;
using MailBee.SmtpMail;
class Sample
{
static void mailer_MessageSent(object sender, SmtpMessageSentEventArgs e)
{
string email = e.MergeDataReaderRowValues[1].ToString();
Console.WriteLine(string.Format("{0} SUCCEEDED", email));
}
static void mailer_MessageNotSent(object sender, SmtpMessageNotSentEventArgs e)
{
string email = e.MergeDataReaderRowValues[1].ToString();
Console.WriteLine(string.Format("{0} FAILED", email));
}
static void Main(string[] args)
{
Smtp mailer = new Smtp("MN100-0123456789ABCDEF-0123");
mailer.Log.Filename = @"C:\Temp\log.txt";
mailer.Log.Enabled = true;
mailer.Log.Format = LogFormatOptions.AddContextInfo;
mailer.Log.Clear();
mailer.MessageSent += new SmtpMessageSentEventHandler(mailer_MessageSent);
mailer.MessageNotSent += new SmtpMessageNotSentEventHandler(mailer_MessageNotSent);
mailer.SmtpServers.Add("mail.domain.com", "jdoe@domain.com", "secret");
mailer.Message.From.AsString = "John Doe <john.doe@domain.com>";
mailer.Message.To.AsString = "##Name## <##Email##>";
mailer.Message.Subject = "Our Oct/2013 newsletter";
mailer.DeliveryNotification.TrackingID = "Oct2013_##ID##";
mailer.Message.BodyHtmlText = "##HTML_body##";
mailer.Message.BodyPlainText = "##Plain_body##";
mailer.Message.Charset = "UTF-8";
mailer.Message.Builder.HtmlToPlainMode = HtmlToPlainAutoConvert.Never;
string connParams = @"server=(local)\SQLEXPRESS;Initial Catalog=afterlogic;Integrated Security=True";
using (SqlConnection conn = new SqlConnection(connParams))
{
conn.Open();
using (SqlCommand command = conn.CreateCommand())
{
command.CommandText = "SELECT * FROM newsletter";
using (SqlDataReader reader = command.ExecuteReader())
{
mailer.AddJob(null, null, null, reader);
mailer.SendJobs();
Console.WriteLine();
if (mailer.JobsFailed.Count == 0)
{
Console.WriteLine(
"All of the rows of the table have been processed and sent as e-mails.");
}
else
{
if (mailer.JobsSuccessful.Count == 0)
{
Console.WriteLine(
"None of the rows of the table has been processed and sent as e-mail.");
}
else
{
Console.WriteLine(
"Not all rows of the table have been processed and sent as e-mails.");
Console.WriteLine();
Console.WriteLine("Successful rows count: " +
mailer.JobsSuccessful.Count.ToString());
Console.WriteLine();
Console.WriteLine("Failed rows count: " +
mailer.JobsFailed.Count.ToString());
}
Console.WriteLine();
mailer.JobsSuccessful.Clear();
mailer.JobsFailed.Clear();
}
}
}
}
}
}
Imports System.Data
Imports System.Data.SqlClient
Imports MailBee
Imports MailBee.Mime
Imports MailBee.SmtpMail
Class Sample
Private Shared Sub mailer_MessageSent(sender As Object, e As SmtpMessageSentEventArgs)
Dim email As String = e.MergeDataReaderRowValues(1).ToString()
Console.WriteLine(String.Format("{0} SUCCEEDED", email))
End Sub
Private Shared Sub mailer_MessageNotSent(sender As Object, e As SmtpMessageNotSentEventArgs)
Dim email As String = e.MergeDataReaderRowValues(1).ToString()
Console.WriteLine(String.Format("{0} FAILED", email))
End Sub
Shared Sub Main(args As String())
Dim mailer As New Smtp("MN100-0123456789ABCDEF-0123")
mailer.Log.Filename = "C:\Temp\log.txt"
mailer.Log.Enabled = True
mailer.Log.Format = LogFormatOptions.AddContextInfo
mailer.Log.Clear()
mailer.MessageSent += New SmtpMessageSentEventHandler(AddressOf mailer_MessageSent)
mailer.MessageNotSent += New SmtpMessageNotSentEventHandler(AddressOf mailer_MessageNotSent)
mailer.SmtpServers.Add("mail.domain.com", "jdoe@domain.com", "secret")
mailer.Message.From.AsString = "John Doe <john.doe@domain.com>"
mailer.Message.[To].AsString = "##Name## <##Email##>"
mailer.Message.Subject = "Our Oct/2013 newsletter"
mailer.DeliveryNotification.TrackingID = "Oct2013_##ID##"
mailer.Message.BodyHtmlText = "##HTML_body##"
mailer.Message.BodyPlainText = "##Plain_body##"
mailer.Message.Charset = "UTF-8"
mailer.Message.Builder.HtmlToPlainMode = HtmlToPlainAutoConvert.Never
Dim connParams As String = "server=(local)\SQLEXPRESS;Initial Catalog=afterlogic;Integrated Security=True"
Using conn As New SqlConnection(connParams)
conn.Open()
Using command As SqlCommand = conn.CreateCommand()
command.CommandText = "SELECT * FROM newsletter"
Using reader As SqlDataReader = command.ExecuteReader()
mailer.AddJob(Nothing, Nothing, Nothing, reader)
mailer.SendJobs()
Console.WriteLine()
If mailer.JobsFailed.Count = 0 Then
Console.WriteLine("All of the rows of the table have been processed and sent as e-mails.")
Else
If mailer.JobsSuccessful.Count = 0 Then
Console.WriteLine("None of the rows of the table has been processed and sent as e-mail.")
Else
Console.WriteLine("Not all rows of the table have been processed and sent as e-mails.")
Console.WriteLine()
Console.WriteLine("Successful rows count: " & mailer.JobsSuccessful.Count.ToString())
Console.WriteLine()
Console.WriteLine("Failed rows count: " & mailer.JobsFailed.Count.ToString())
End If
Console.WriteLine()
mailer.JobsSuccessful.Clear()
mailer.JobsFailed.Clear()
End If
End Using
End Using
End Using
End Sub
End Class
See Also