smsohan / MvcMailer

A Mailer for ASP.Net MVC that forms the Email Body using MVC Views (Razor etc.) following Ruby on Rails ActionMailer style
MIT License
585 stars 176 forks source link

Change Values in Email Template dynamically #135

Open devbhagat2003 opened 10 years ago

devbhagat2003 commented 10 years ago

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