Emails notificationhttp://forums.asp.net/t/1792338.aspx/1?Emails+notificationFri, 13 Apr 2012 05:37:49 -040017923384929985http://forums.asp.net/p/1792338/4929985.aspx/1?Emails+notificationEmails notification <p>HEY ALL</p> <p>Would like a few sample coding on how to email a list of recipents with there own unique information using a plaint text or html template.</p> <p>template Example</p> <p>&lt;html&gt;<br> &lt;head&gt;<br> &lt;title&gt;Welcome to &lt;/title&gt;<br> &lt;/head&gt;<br> &lt;body&gt;<br> &lt;p&gt;Dear &lt;%Name%&gt;,&lt;/p&gt;<br> &lt;p&gt;An account has been created for you.&lt;/p&gt;<br> &lt;p&gt;Your account is FREE and allows you to perform bla bla features.&lt;/p&gt;<br> &lt;p&gt;To login and complete your profile, please go to:&lt;/p&gt;<br> &lt;p&gt;&lt;a href=&quot;&quot;&gt;&lt;%LogOnUrl%&gt;&lt;/a&gt;&lt;/p&gt;<br> &lt;p&gt;Your User ID is your email address and password is: &lt;%Password%&gt;&lt;/p&gt;<br> &lt;/body&gt;<br> &lt;/html&gt;</p> <p>WOULD LIKE TO KNOW HOW TO TAKE THE TEMPLATE AND TRANSFORM THIS INTO A FORMATTED MESSAGE WITH REQUIRED FIELDS FILLED OUT, THEN STORE THAT FORMATTED MESSAGE LIKE IN A REPOSITORY.</p> <p></p> <p></p> <p></p> 2012-04-12T21:03:11-04:004930257http://forums.asp.net/p/1792338/4930257.aspx/1?Re+Emails+notificationRe: Emails notification <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MakeMe</h4> HOW TO TAKE THE TEMPLATE AND TRANSFORM THIS INTO A FORMATTED MESSAGE WITH REQUIRED FIELDS FILLED OUT</blockquote> <p></p> <p>var text = ////</p> <p>formattedText = text.Replace(&quot;%Name%&quot;, yourName).Replace(....)</p> <p></p> <blockquote><span class="icon-blockquote"></span> <h4>MakeMe</h4> HEN STORE THAT FORMATTED MESSAGE LIKE IN A REPOSITORY.</blockquote> <p></p> <p>Store in a database table.</p> <p></p> 2012-04-13T03:56:17-04:004930375http://forums.asp.net/p/1792338/4930375.aspx/1?Re+Emails+notificationRe: Emails notification <p>Hello,</p> <p>I am storing email templates as normal asp webpages. For example, i have an email template</p> <pre class="prettyprint">@model EmailTemplate @{ Layout = null; } &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Thank you for Registration&lt;/title&gt; &lt;/head&gt; &lt;body&gt; Hello @Model.FirstName, &lt;br/&gt; Thank you for registering. Your username is: @Model.UserName &lt;br/&gt; Your password is: @Model.Password &lt;/body&gt; &lt;/html&gt;</pre> <p>Then, from code behind, i am getting the page html content.</p> <p>This is the static method</p> <pre class="prettyprint">public static string GetViewPageHtml(Controller controller, object model, string viewName) { ViewEngineResult result = ViewEngines.Engines.FindPartialView(controller.ControllerContext, viewName); if (result.View == null) throw new Exception(string.Format("View Page {0} was not found", viewName)); controller.ViewData.Model = model; StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) { using (HtmlTextWriter output = new HtmlTextWriter(sw)) { ViewContext viewContext = new ViewContext(controller.ControllerContext, result.View, controller.ViewData, controller.TempData, output); result.View.Render(viewContext, output); } } return sb.ToString(); }</pre> <p><br />And i call it from a Controller, like this:</p> <pre class="prettyprint">public ActionResult SendEmail() { var viewPageModel = CreateEmailTemplateModel(); string emailTemplate = GetViewPageHtml(this, viewPageModel, "~/Views/EmailTemplates/RegistrationSuccess.cshtml"); // now send the emailTemplate as "body" }</pre> <p>Is very easy to update the template, and you are working on a real web page<img src="http://forums.asp.net/scripts/tiny_mce/plugins/emotions/img/smiley-wink.gif" alt="Wink" title="Wink" class="emoticon" border="0"></p> 2012-04-13T05:37:49-04:00