In this article I’m going to explain how to send email using HTML template or HTML formatted email in ASP.NET.

      While working with send email from ASP.NET application I have found the solution to send email with HTML template. Please follow the steps I have given below.

          First we have to create HTML page. Add NewItem ->HTML pageDesign your HTML page like this

Example: SendMail.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

    <title>Email</title>

</head>

<body>

<div>

  <table style="font-family:Calibri;background:#E6E6E6" >

  <tr>

       <td><p>Dear [MyName]</p>

       <p>Thanks for your subscription</p>

       </td>

  </tr>  

</table>

</div>

</body>

</html> 

          In above code you’ll be noticed that Yellow color, here I have created placeholder for replace the string. 

          Here we have to configure email setting in we.config. 

          <appSettings>

                   <add key="Email" value="example@gmail.com"/>

                   <add key="Password" valueyour password"/>

                   <add key="MailServer" value="smtp.gmail.com"/>

                   <add key="MailPort" value="587"/>

                   <add key="IsSSLEnabled" value="true"/>

          </appSettings>

  

Then design your aspx page like this

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">

    <title>HTML mail</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

       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"/>

    </div>

    </form>

</body>

</html>

 

C# code:

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Net.Mail;

using System.IO;

using System.Configuration; 

public partial class _Default : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {    }

    protected void btnSubmit_Click(object sender, EventArgs e)

    {       

        try  {

            MailMessage Msg = new MailMessage();

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

            Msg.To.Add(txtEmail.Text);

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

            string readFile = reader.ReadToEnd();

            string StrContent = "";

            StrContent = readFile;

            //Here replace the name with [MyName]

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

 

            Msg.Subject = "Dotnetfox - Thanks for your subscription";

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

           

            smtp.Send(Msg);

        }

        catch (Exception ex)

        { }

    }

}

 

cytotec abortion

an abortion pill buy abortion pills online
medical abortion pill online abortion pill abortion pill


View demo Download
http://www.dotnetfox.com/Document/1091/0photo2.jpeg

If you enjoyed this article, get email updates (it's free).


Related Articles
  • Send Mail using ASP.NET with C#In this article I'm going to explain how to send email in ASP.NET application using C#. ASP.NET allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP). Here I’ll explain Namespace, Classes, Properties and Methods which are all used to send mail from ASP.NET application.
  • Send Mail- How to configure SMTP Mail Settings defined in Web.Config File In this article i'm going to explain how to Send Mail with configure SMTP Mail Settings defined in Web.Config File using ASP.NET with C#. ASP.NET allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP). Here I’ll show you how to configure smtp mail settings defined in web.config file.
  • Send Email using HTML template or HTML formatted email in ASP.NETIn this article I’m going to explain how to send email using HTML template or HTML formatted email in ASP.NET. while working with send email from ASP.NET application I have found the solution to send email with HTML template. Please follow the steps I have given below. First we have to create HTML page. Add NewItem ->HTML page. In above code you’ll be noticed that Yellow color, here I have create...

Comments
comments powered by Disqus

Thanks for downloading..!!

×
Subscribe via Email
    
message to display in fancybox