Dynamic fields in .msg file


I've created a email template in Outlook and saved it as a .Msg file. I want to put dynamic fields in the email body. How can I use Aspose.Email to populate these dynamic fields.

See attached example, I have #Name# where i get the persons name from a database. How can I replace these fields in the .Msg file?



Hi Arjuna,

Thank you for using Aspose.Email.

Please refer to the following code that performs the task you are in need of. Please let us know if you have any additional query/inquiry related to Aspose.Email.

C# Sample Code:

MailMessage mailMsg = MailMessage.Load("AsposeTemplate.msg");

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

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

//Create an instance of DataRow
DataRow dr;
dr = dt.NewRow();
dr["Name"] = "Kashif";

MailMessageCollection messages;
    //Create messages from the message and datasource.
    messages = engine.Instantiate(dt);
    MailMessage msg = messages[0];

    //Save the message
    msg.Save("Test.msg", MailMessageSaveType.OutlookMessageFormat);

    //or send it using Smtp
    //Create an instance of SmtpClient and specify server, port, username and password
    SmtpClient client = new SmtpClient("smtp.server.com", 25, "username", "password");

    //Send messages in bulk
catch (MailException ex)
catch (SmtpException ex)