a blog by jeff lafay, software developer
December 20, 2011 StackOverflow that I answered. Building email message content via string concats can be a huge pain to implement (not to mention pretty boring).
My method for email templating with C# is sweet and simple. It works by reading the text from a template file at runtime, retrieving a model object, and then passing both to the Razor parser to render the needed email body with the model property values populated. Since the templates are read at runtime, small cosmetic tweaks to your email templates are easy.
Here's a breakdown of what you need
- Reference RazorEngine (Nuget package available)
- Create a template file
- Render email body with RazorEngine's parser