I am building an application which will send out custom emails to end users.
I have constructed an HTML template from which the emails will be built.
I currently have the template filled with tags as placeholders for the custom content…
|Text-Placeholder|
I have been returning the html file as a string to my CreateEMail Method:
string html = System.IO.File.ReadAllText(Server.MapPath("~/EmailTemplates/emailTemplate.html"));
And then using String.Replace to substitute in the custom text/content
html = html.Replace("|Name-Placeholder|", username);
I am curious if there is a method which would allow me to construct the template as a RazorView strongly typed as a ViewModel which will model the custom text/content, and return the view as an HTML file or directly as a string to pass into the body property of my SMTPClient instance for sending to the user?
Has anyone accomplished something like this or similar?
Have a look at these libraries:
There is ActionMailer. Inspired by Ruby’s ActionMailer.
http://nuget.org/packages/ActionMailer
Supports many view engines I think, Razor included of course. And allows you to pass a model into the view. See:
https://bitbucket.org/swaj/actionmailer.net/wiki/Home
The code :
The view:
There is also another library:
http://nuget.org/packages/MvcMailer
https://github.com/smsohan/MvcMailer