Sending Email By Using Email Templates In ASP.NET WebForm

What are Email Templates?
Email templates is a predefined body of text of email messages. Sending email is just about filling in the blank fields.
We can send Email through coding . For this the following things are required :-
  1. Email Account
  2. Email Account SMTP Detail.
  3. Code of Email Sending: In dot net framework there are two namespaces, System.Net, System.Net.Mail required.
make email template
 //Fetching Email Body Text from EmailTemplate File.  
        string FilePath = "D:\\MBK\\SendEmailByEmailTemplate\\EmailTemplates\\SignUp.html";  
StreamReader str = new StreamReader(FilePath);  
string MailText = str.ReadToEnd();  
str.Close();

 // server code
          MailMessage mail = new MailMessage();//object created
        //Setting From , To and CC

        mail.To.Add(TextBox1.Text);
        mail.From=new MailAddress("email id ");
        mail.Subject="thanks for Registartion";
        mail.Body=MailText;
        mail.IsBodyHtml=true;// it will convert msg format in html
        //smtp object

        SmtpClient smtp= new SmtpClient();
        smtp.Host="smtp.gmail.com";
        smtp.Credentials=new System.Net.NetworkCredential("email","pass");//email id & password
        smtp.EnableSsl=true;// server security licence will true then only mail will send
        smtp.Send(mail);//send function with mail object pass...which will send mail.

Popular Posts