I have the following function that generates the body of an email based on an HTML file:
private string createEmailBody(string userName, string title, string message)
{
string body = string.Empty;
//using streamreader for reading my htmltemplate
using(StreamReader reader = new StreamReader(Server.MapPath("~/HtmlTemplate.html")))
{
body = reader.ReadToEnd();
}
body = body.Replace("{UserName}", userName); //replacing the required things
body = body.Replace("{Title}", title);
body = body.Replace("{message}", message);
return body;
}
This function was written a few years ago. Is there any newer way to send HTML formatted email? (I researched in SO but found only old questions from 5 years ago and more.)
I'm using this code in my Web API to send confirmation emails to new registers.