Wednesday, February 11, 2015

Sending Email Using HTML File template the proper way

Sending Email Using HTML File template the proper way 

- Some Developers using variant methods to send email using html file some of them don't know the magic .Net Class "MailDefinition" .

    /// <summary>
        /// .Net Way To Send Email Using HTML Template File
        /// Using Magic Of 'MailDefinition'
        /// </summary>
        private void OtherDotNetNormalWayToSendEmailTemplate()
            //How To Use Html Template To Send Email
            string htmlBodyTemplatePath = System.Web.HttpContext.Current.Server.MapPath("~/EmailTemplates/EmailTemplateTest.html");
            MailDefinition mailDefinition = new MailDefinition();
            mailDefinition.BodyFileName = Server.MapPath(htmlBodyTemplatePath);
            mailDefinition.From = "xxx";
            mailDefinition.CC = "xxx";
            mailDefinition.IsBodyHtml = true;
            mailDefinition.Subject = "xxxx";
            System.Collections.Specialized.ListDictionary replacements = new System.Collections.Specialized.ListDictionary();
            replacements.Add("<%RegDate%>", "XXX");
            replacements.Add("<%UserName%>", "XXXX");
            replacements.Add("<%UserFullName%>", "XXX");
            System.Net.Mail.MailMessage msg = mailDefinition.CreateMailMessage("XXX", replacements, new System.Web.UI.Control());
            msg.From = new System.Net.Mail.MailAddress("XX", "XXX");
            SmtpClient smtpClient = new SmtpClient();


1 comment:

Unknown said...
This comment has been removed by a blog administrator.