Follow Us

LightBlog

Breaking

Monday, September 10, 2018

sending mail


using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.Net.Mail;

public partial class contactus : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
        {

            {
                SendMailToClient();
                SendMailToAdmin();
                lblConfirmation.Visible = true;
            }

        }
    }
    protected void SendMailToClient()
    {

        using (MailMessage mm = new MailMessage())
        {

            string sClientMessage = "";
            sClientMessage = "<table width=\"600px\" cellspacing=\"1\" cellpadding=\"2\" style=\"font-family:arial; font-size:12px;\">";
            sClientMessage += "<tr><td align=\"left\" ><b>Thank you for contacting us!</b><br/><br/><br/>Your information has been sent and we should be in touch with you soon.<br/><br/>You should expect a personal reply within the day or even sooner - as we answer most email within a few hours.<br/><br/>Feel free to contact us bharatvisionevents.com if you have any questions.We hope that our <a href=\"www.bharatvisionevents.com\" target=\"_blank\">www.bharatvisionevents.com</a> portal works well for your requirement. If there is anything we can do to help - please don't hesitate to let us know!</td></tr>";
            sClientMessage += "<tr><td><br /><br /> Regards,<br /><br /> bharatvisionevent <br /></td></tr>";
            sClientMessage += "</table>";



            mm.From = new MailAddress("info@bharatvisionevents.com");
            mm.To.Add(txtemail.Text); //---- Email address of the recipient.
            mm.Subject = "Confirmation Mail bharatvisionevents.com";  //---- Subject of email.
            mm.Body = sClientMessage; //---- Content of email.
            mm.IsBodyHtml = true; //---- To specify wether email body contains HTML tags or not.

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com"; //---- SMTP Host Details.
            smtp.EnableSsl = true; //---- Specify whether host accepts SSL Connections or not.
            NetworkCredential NetworkCred = new NetworkCredential("info@bharatvisionevents.com", "@0512");
            //---Your Email and password
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 587; //---- SMTP Server port number. This varies from host to host.
            smtp.Send(mm);
        }

    }
    protected void SendMailToAdmin()
    {
        using (MailMessage mm = new MailMessage())
        {
            //change it only
            string sMessage = "";
            sMessage = "<table width=\"600px\" cellspacing=\"1\" cellpadding=\"2\" style=\"font-family:arial; font-size:12px;\">";
            sMessage += "<tr><td colspan=\"3\">Hi, <br /><br /> Mr./Mrs. " + txtname.Text + " Send Enquiry:<br /><br /></td></tr>";
            sMessage += "<tr><td align=\"left\" width=\"50%\" style=\"background-color: #C1D2FF; padding-left:10px;\">Name :</td> <td align=\"left\" style=\"background-color: #9DB8FF; padding-left:10px;\">" + txtname.Text + "</td></tr>";
            sMessage += "<tr><td align=\"left\" width=\"50%\" style=\"background-color: #C1D2FF; padding-left:10px;\">Email Id:</td> <td align=\"left\" style=\"background-color: #9DB8FF; padding-left:10px;\">" + txtemail.Text + "</td></tr>";
            sMessage += "<tr><td align=\"left\" width=\"50%\" style=\"background-color: #C1D2FF; padding-left:10px;\">Mobile No:</td> <td align=\"left\" style=\"background-color: #9DB8FF; padding-left:10px;\">" + txtmobile.Text + "</td></tr>";

            sMessage += "<tr><td align=\"left\" width=\"50%\" style=\"background-color: #C1D2FF; padding-left:10px;\">Message:</td> <td align=\"left\" style=\"background-color: #9DB8FF; padding-left:10px;\">" + txtmessage.Text + "</td></tr>";


            sMessage += "</table>";
            //change it only

            mm.From = new MailAddress("info@bharatvisionevents.com"); //--- Email address of the sender
            mm.To.Add("info@bharatvisionevents.com"); //---- Email address of the recipient.
            mm.Subject = "Contact Us Inquiry Mail From " + (txtemail.Text); //---- Subject of email.
            mm.Body = sMessage; //---- Content of email.
            mm.IsBodyHtml = true; //---- To specify wether email body contains HTML tags or not.

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com"; //---- SMTP Host Details.
            smtp.EnableSsl = true; //---- Specify whether host accepts SSL Connections or not.
            NetworkCredential NetworkCred = new NetworkCredential("info@bharatvisionevents.com", "");
            //---Your Email and password
            smtp.UseDefaultCredentials = true;
            smtp.Credentials = NetworkCred;
            smtp.Port = 587; //---- SMTP Server port number. This varies from host to host.
            smtp.Send(mm);
         
           lblConfirmation.Text = "Congratulations, Your email successfully sent";

            txtname.Text = "";
            txtemail.Text = "";
            txtmobile.Text = "";
         
            txtmessage.Text = "";





        }
    }
}

No comments:

Post a Comment