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

Free Support Forum - aspose.com

Mapping data to an email message

I’m mapping data to an email message seemingly successfully, but the resulting email often shows the data columns rather than the data. It looks like this:
Testing these fields:
Data in Column 1 //this is correct
Data in Column 2 //this is correct
#Column3# //this is incorrect
End Test

Hi,


Thank you for considering Aspose and welcome to the Aspose.Email forum.

Can you please post us your sample application exhibiting your said issue. We will look into it very soon and provide you all the assistance you may require to resolve this issue.
The project I use this in is quite large. It will take me some time to get around to creating a smaller one. Here

is the html going in and coming out of:
TemplateEngine engine = new TemplateEngine(MessageOptions.message);
MailMessageCollection messages = engine.Instantiate(MessageOptions.MessageData,MessageOptions.columnMap);

I pass in a DataTable with one DataRow.The Columns are "DrawingName", "Artist", and "IndexedDate". The values are

"Mona Lisa", "da Vinci", and Today's Date.ToString().

Here is the html in MessageOptions.message with the Column Names enclosed with #:

Testing these fields:

#DrawingName#

#Artist#

#IndexedDate#

 

End Test


Here is the html generated with the Column Names replaced using column mapping:

Testing these fields:

Mona Lisa

da Vinci

#IndexedDate#

 

End Test


The first two columns mapped correctly.

Thanks for the help.

Hi,


Thank you for providing us the further details. We will start testing for your said issues on the same lines. But it would be of great help that you give us a small sample (console) application to reproduce the issue more quickly and easily.

We will keep you posted on this. Thanks again for your patience and understanding.

Hi,


I have put up an example with latest version of Aspose.Email for .NET v1.0.0 and I did not notice any issue as stated by you. Moreover, I believe you are using some older version of Aspose.Network for .NET (Aspose.Network has been renamed to Aspose.Email recently). In current version there is no constructor for TemplateEngine that accepts MessageOptions object as an argument. Instead, we have exposed a new interface for mail merge that supports “Data Column Mapping” feature. You can build a DataColumnMappingCollection to map the columns.

Please check the below source code for your reference.

MailMessage template = new MailMessage();
//add template field to subject
template.Subject = “Hello, #FirstName#”;
template.From = new MailAddress("dgertz@mycompay.com", "dgertz@mycompay.com");
//add template field to receipt
template.To.Add(new MailAddress("#Receipt#", true));
//add template field to html body
template.HtmlBody = “Dear #FirstName# #LastName#
Sent Date : #Date#”;
//create a new TemplateEngine with the template message.
TemplateEngine engine = new TemplateEngine(template);

//fill a DataTable as data source
DataTable dt = new DataTable();
dt.Columns.Add(“Receipt”, typeof(string));
dt.Columns.Add(“First Name”, typeof(string));
dt.Columns.Add(“Last Name”, typeof(string));
dt.Columns.Add(“Date”, typeof(DateTime));
DataRow dr;

dr = dt.NewRow();
dr[“Receipt”] = "aaa@hotmail.com";
dr[“First Name”] = “Nancy”;
dr[“Last Name”] = “Davolio”;
dr[“Date”] = System.DateTime.Now;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr[“Receipt”] = "aaabb@hotmail.com";
dr[“First Name”] = “Andrew”;
dr[“Last Name”] = “Fuller”;
dr[“Date”] = System.DateTime.Now;
dt.Rows.Add(dr);

dr = dt.NewRow();
dr[“Receipt”] = "bbb@163.com";
dr[“First Name”] = “Janet”;
dr[“Last Name”] = “Leverling”;
dr[“Date”] = System.DateTime.Now;
dt.Rows.Add(dr);

DataColumnMappingCollection mappings = new DataColumnMappingCollection();
mappings.Add(new DataColumnMapping(“Receipt”, “Receipt”));
mappings.Add(new DataColumnMapping(“First Name”, “FirstName”));//map the “First Name” to FirstName column
mappings.Add(new DataColumnMapping(“Last Name”, “LastName”));
mappings.Add(new DataColumnMapping(“Date”, “Date”));
MailMessageCollection messages;
try
{
//Create messages from the message and datasource.
messages = engine.Instantiate(dt, mappings);
for (int i = 0; i < messages.Count; i++ )
{
messages[i].Save(“C:\temp\test”+i+".eml", MailMessageSaveType.EmlFormat);
}
}
catch (MailException ex)
{
System.Diagnostics.Debug.WriteLine(ex.ToString());
}

Using the Source Demo that comes with the new Aspose.Email, I altered the DataTable to have the same three columns as my example and I used the same html string in the textbox_message.Text. I got the same exact results that I’ve posted.

Hi,

Thank you for further information.

I am able to reproduce your said issue with this [sample project](https://apps.banckle.com/file/g/?v=tvzd9irNkmJ&f=MailMerge.zip). So I have recorded an investigative ticket in our bug tracking system under ticket ID 31579. We will look into this matter very soon and keep you posted with updates.

Regards,

The issues you have found earlier (filed as 31579 ) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.