I have an asp.net web application, which sends several emails to users during the signup procedure. Right now I have them inline with the code, but I would like to hold them in a central location where I can edit them without going in to VS.
What would be the best place/format to store these HTML templates?
I store all my e-mail templates for my web-app as ASP.NET MVC Razor Views, but as embedded resource in a light assembly that I can easily reference from any project.
A template looks like this (notice the localization):
Then I have a “master” template, called
_AppEmailTemplate.cshtml:To actually send the e-mail, I use RazorEngine for rendering:
The above code uses my own EmailDto object. Here you can easily create a
[MailMessage][2]instance directly, and send it using the[SmtpClient][3].Also, to get the best rendering in all e-mail clients, I use my own PreMailer.Net library to move all CSS inline. Read my blog post here, for more information. (Code is on Github)
The GetEmailTemplate does this: