// Prepare the data.
//We will create a offline datatable to demonstrate , this can veru well
//be fetched from database.
this.AddLogEntry("Creating the data.");
#region Create Data
DataSet dsOrderData = new DataSet();
#region Create Data
// We create a datatable
DataTable tb = new DataTable("ORDERS");
tb.Columns.Add("FIRSTNAME");
tb.Columns.Add("DATE", typeof(DateTime));
tb.Columns.Add("CODEFORMATEDDATE", typeof(DateTime));
tb.Columns.Add("CODEFORMATEDNUMBER", typeof(float));
// We create sample set of data
DataRow dr = tb.NewRow();
dr["FIRSTNAME"] = "John";
dr["DATE"] = DateTime.Now;
dr["CODEFORMATEDDATE"] = DateTime.Now;
dr["CODEFORMATEDNUMBER"] = 0.58;
tb.Rows.Add(dr);
dsOrderData.Tables.Add(tb);
#endregion
#endregion
this.AddLogEntry("Creating templater.");
ActiveUp.Net.Mail.Templater templater =
new ActiveUp.Net.Mail.Templater("mailformat_working_with_field_format.xml");
// We instanciante the Merger object by passing the templater data.
Merger merger = new Merger(templater);
//Either you can specifiy the field format in the XML using <fieldformat>
//tags are you can add the field format in the code
merger.FieldsFormats.Add("CODEFORMATEDDATE", "{0:dd mmm yy}");
merger.FieldsFormats.Add("CODEFORMATEDNUMBER", "{0:0#.##0}");
// We merge our message with the data.
merger.MergeMessage(dsOrderData.Tables[0]);
this.AddLogEntry("Sending template message.");
//Handle the error in case any
try
{
merger.Message.Send("localhost");
this.AddLogEntry("Message sent successfully.");
}
catch (SmtpException ex)
{
this.AddLogEntry(string.Format("Smtp Error: {0}", ex.Message));
}
catch (Exception ex)
{
this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
}