MvcMailer
MvcMailer copied to clipboard
Change Values in Email Template dynamically
Hi there, Before sending email, I want to update the couple of template fields. like User name, Email etc.
Whatever is there in Welcome.cshtml, this is sent as an email. But let's say I have a parameter in template {userName} which is unique for every user.
How Can I update this, before sending email.
Sample Code which I am trying to achieve:-
string emailBody = string.Empty; using (StreamReader reader = new StreamReader(Server.MapPath("~/Views/UserMailer/Welcome.cshtml"))) { emailBody = reader.ReadToEnd(); } emailBody = emailBody.Replace("{NAME}", "Davinder Kumar"); emailBody = emailBody.Replace("{EMAILADDRESS}", email);
mailer.Welcome(email, emailBody).SendAsync();