.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Sandeep Singh
Melody Anderson
Eminent IT

Home >> Articles >> ASP.NET >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Sending Emails with HTML templates

Posted By:Ashutosh Jha       Posted Date: March 30, 2014    Points: 200    Category: ASP.NET    URL: http://www.dotnetspark.com  

In this article i am going to explain, how to sending emails in asp.net with the html templates design.

Design a template and name it (suppose mailtemp.htm).

Then create your main page as like this (name - mainpage.aspx).



       Name: <asp:TextBox ID="txtName" runat="server"></asp:TextBox><br />

       Email-ID: <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox><br />

        <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click"/>


Their aspx.cs - upon button click write this method-

protected void btnSubmit_Click(object sender, EventArgs e)


        try  {

            MailMessage Msg = new MailMessage();

            Msg.From = new MailAddress(ConfigurationManager.AppSettings["Email"]);


            StreamReader reader = new StreamReader(Server.MapPath("~/mailtemp.htm "));

            string readFile = reader.ReadToEnd();

            string StrContent = "";

            StrContent = readFile;

            //Here replace the name with [MyName]

            StrContent = StrContent.Replace("[MyName]", txtName.Text);


            Msg.Subject = " Thanks ;

            Msg.Body = StrContent.ToString();

            Msg.IsBodyHtml = true;

            // your remote SMTP server IP.

            SmtpClient smtp = new SmtpClient();

            smtp.Host = ConfigurationManager.AppSettings["MailServer"];

            System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();

            NetworkCred.UserName = ConfigurationManager.AppSettings["Email"];

            NetworkCred.Password = ConfigurationManager.AppSettings["Password"];

            smtp.UseDefaultCredentials = true;

            smtp.Credentials = NetworkCred;

            smtp.Port = int.Parse(ConfigurationManager.AppSettings["MailPort"]);

            smtp.EnableSsl = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSSLEnabled"].ToString());





 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend