Create a new message
So first create the message and adjust some settings. CultureInfo
is relevant for formatting placeholders that contain dates, currency or numeric data.
The real advantage of MailMergeLib comes from placeholders. {Placeholders} are the field names of a DataTable
embedded in any text with curly braces.
MailMergeMessage mmm = new MailMergeMessage("My subject for {Nickname}");
mmm.CharacterEncoding = Encoding.GetEncoding("iso-8859-1");
mmm.CultureInfo = new System.Globalization.CultureInfo("en-US");
mmm.TextTransferEncoding = System.Net.Mime.TransferEncoding.SevenBit;
mmm.BinaryTransferEncoding = System.Net.Mime.TransferEncoding.Base64;
Attachments
You may also want to add some personalized attachments by adding placeholders to the file name. E.g.:
mmm.FileAttachments.Add(new FileAttachment("testmail_{Nickname}.pdf", "sample.pdf", "application/pdf"));
And that's the way to add string attachments:
mmm.StringAttachments.Add(new StringAttachment("Some programmatically created content", "file.txt", "text/plain"));