Take the 2-minute tour ×

I want to send a HTML email using HTML template. I would like to just replace some value's from that HTML template. Any idea how to achieve this?

share|improve this question
This question has been answered here before: http://stackoverflow.com/questions/620265/can-i-set-up-html-email-templates-in-‌​c-on-asp-net –  Alison R. Nov 20 '09 at 14:50
add comment

4 Answers

If your needs are more complex than can be achieved with @Anuraj's suggestion then I'd suggest looking at XSLT - you package your data as a lump of XML and transform the XML into whatever (HTML in this case) using an XSLT template.

Support in .NET for this kind of transformation is excellent and once you have got over the initial challenges (XSLT is different) you will have added a very capable set of tools to your toolkit.

share|improve this answer
add comment
string emailTemplate = @"
bla bla bla dear ##USERNAME## bla bla bla!

Best regards, 

string email = emailTemplate
    .Replace("##USERNAME##", userName)
    .Replace("##MYNAME##", myName);
share|improve this answer
add comment

Place place holders in the HTML content with {0},{1} etc and use String.format() to replace it.

share|improve this answer
add comment

DotLiquid is another option. You specify values from a class model as {{ user.name }} and then at runtime you provide the data in that class, and the template with the markup, and it will merge the values in for you. The nice thing is these are "safe" so that user's who create the templates can't crash your system or write unsafe code: http://dotliquidmarkup.org/try-online

share|improve this answer
add comment

Your Answer


