MvcMailer icon indicating copy to clipboard operation
MvcMailer copied to clipboard

Change Values in Email Template dynamically

Open devbhagat2003 opened this issue 10 years ago • 0 comments

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();

devbhagat2003 avatar Jun 18 '14 06:06 devbhagat2003