We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Template Engine datatable column value with special characters not kept in merged message


I need your assistance on figuring out how to make sure the data table data that has special characters (language dependent) is properly handled by the TemplateEngine, the code:

TemplateEngine engine = new TemplateEngine(msg);

messages = engine.Instantiate(myEmailTable);

MailMessage msg1 = engine.Merge(myEmailTable[RowInQuestion]);

1. The placeholder in the template msg.HtmlBody which is also the myEmailTable column-name[ElectionDescription] includes:
msg.HtmlBody += "...#ElectionDescription#..."

2. A myEmailTable datatable row data in question for the ElectionDescription Column shows:

3. The merged messages msg1.htmlbody for the row in question is not properly showing special characters as they are in the data-table, it shows:


4. Note that other special characters in msg.HtmlBody += "...." are shown properly. That is characters that do not come from myDataTable data but that are part of the template msg.HtmlBody will show correctly in the merged message msg1.HtmlBody. Again Special characters are failing only for the dynamic data, that is data where the place holders are replaced with data coming from myEmailTable rows.

5. The above data in 2. and 3. was taken from running code debug session

6. I tried utilizing

msg.PreferredTextEncoding = Encoding.Unicode; in the templated message but then merging fails

7. I tried utilizing

msg1.PreferredTextEncoding = Encoding.Unicode; in the merged message but then nothing happens

8. Tried utilizing BodyEncoding, etc. on messages both UTGF8 and Unicode with no success

Any ideas?



Hi Luis,

Thank you for contacting Aspose Support team.

We have tested this issue with the latest version of the API i…e. Aspose.Email for .NET 6.3.0 and were not able to reproduce the problem at our end. Please have a look at the following sample code and attached files that have been used while testing the problem. It seems the issue may be specific to your template MSG file. Please share your sample MSG files and complete code with us for further assistance in this regard.

Sample Code:

//Create a new MailMessage instance
MailMessage msg = MailMessage.Load(@“MyTemplate.msg”, new MsgLoadOptions());

//Add subject and from address
msg.Subject = “Hello, #FirstName#”;
msg.From = "sender@sender.com";

//Add email address to send email

//Create a new TemplateEngine with the MSG message.
TemplateEngine engine = new TemplateEngine(msg);

//Create an instance of DataTable
//Fill a DataTable as data source
DataTable dt = new DataTable();
dt.Columns.Add(“GivenName”, typeof(string));

//Create an instance of DataRow
DataRow dr;

dr = dt.NewRow();
dr[“GivenName”] = “ELECCIÓN PRIMARIA”;

MailMessageCollection messages;
//Create messages from the message and datasource.
messages = engine.Instantiate(dt);

foreach (MailMessage msg1 in messages)
msg1.Save(@“Resaved.msg”, Aspose.Email.Mail.SaveOptions.DefaultMsgUnicode);
catch (MailException ex)

catch (SmtpException ex)

Hello Thanks for your reply.

By the way did you try using the merge line? I don’t see that in your example

Please try using the merge line I provided and let me know.



Hi Luis,

I have included the Merge statement as well and generated the message files. It is observed that both the files are same and no issue is observed. Could you please give a try to attached sample code and compare the output files with the attached files?