-
Notifications
You must be signed in to change notification settings - Fork 32
Home
Norbert Bietsch edited this page Aug 28, 2016
·
20 revisions
var variables = new Dictionary<string, object>() { { "Email", "[email protected]" }, {"Name", "John Specimen"} };
// create a new message with plain text and HTML body parts
// Placeholders are the variable names in curly braces
var mmm = new MailMergeMessage("Personal message for {Name}", "This is pure text for {Name}",
"<html><head><title>No title</title></head><body>This is HTML text for {Name}</body></html>");
// want to see how the final message will look like? Just save it to file and explore.
// mmm.GetMimeMessage(variables).WriteTo("enter-your-filename-here.eml");
mmm.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.From, "[email protected]"));
mmm.MailMergeAddresses.Add(new MailMergeAddress(MailAddressType.To, "{Name}", "{Email}"));
var mms = new MailMergeSender();
mms.MaxNumOfSmtpClients = 1; // enough for a single email
mms.Config.SmtpClientConfig[0].MessageOutput = MessageOutput.SmtpServer;
mms.Config.SmtpClientConfig[0].ClientDomain = "mail.sample.com";
mms.Config.SmtpClientConfig[0].SmtpHost = "smtp.mailprovider.net";
mms.Config.SmtpClientConfig[0].SmtpPort = 587;
mms.Config.SmtpClientConfig[0].NetworkCredential = new Credential("username", "password");
mms.Config.SmtpClientConfig[0].MaxFailures = 3;
mms.Send(mmm, variables);
Simply replace the variables part from the sample above with this:
var variables = new[]
{
new {
Email = "[email protected]",
Name = "John Specimen",
},
new {
Email = "[email protected]",
Name = "Mary Specimen",
}
};