<appSettings> In the webconfig file add this
<add key="to" value="cparole@imtsus.com"/>
<add key ="to" value="druiz@imtsus.com"/>
<add key ="to" value="rmiller@imtsus.com"/>
<add key ="to" value="rdasan@imtsus.com"/>
<add key="from" value="avilparackal@gmail.com"/>
<add key="id" value="Ur gmail"/>
<add key="pswd" value="Password""/>
<add key="port" value="587"/>
<add key="smtp" value="smtp.gmail.com"/>
</appSettings>
private void sendmail()
{
try
{
str_mailer.Append(@"<b>Name : </b> " + txtsubject.Text);
str_mailer.Append(@"\n\n\n\ <b>Email Address : </b>" + txtmessage.Text );
str_mailer.Append(@"<br/><b>Phone No : </b>" + txtTo.Text);
//str_mailer.Append(@"<br/><b>Type Of Service : </b>" + dd_select.Text );
//str_mailer.Append(@"<br/><b>Estimated Budget : </b>" + dd_budget.Text);
//str_mailer.Append(@"<br/>" + "<b>Comment : </b>" + txt_comment.Text );
//str_mailer.Append(@"<br/>" + "<b>How Did You hear about Us : </b>" + txtget_id.Text);
//below line m giving sender's email address and receiever's email address that is also mentioned inside the <appSettings></appSettings> in the web.config file
// and m also giving str_mailer.ToString() , in the str_mailer.ToString() coming completed message with the html tags
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(ConfigurationManager.AppSettings["id"], ConfigurationManager.AppSettings["to"], "Info", str_mailer.ToString());
//below line m giving sender's email address and password of that email that is mentioned inside the <appSettings></appSettings> in the web.config file
System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["id"], ConfigurationManager.AppSettings["pswd"]);
//below line m giving smtp and port no: that is also mentioned inside the <appSettings></appSettings> in the web.config file
System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient(ConfigurationManager.AppSettings["smtp"], Convert.ToInt32(ConfigurationManager.AppSettings["port"]));
//System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);
//below m setting some important properties that is necessary to send the email
mailClient.EnableSsl = true;
//below property IsBodyHtml in true because inside the stringbuilder am using some HTMl tags
mail.IsBodyHtml = true;
mailClient.UseDefaultCredentials = false;
mailClient.Credentials = mailAuthentication;
mailClient.Send(mail);
// when all the process will be completed then a message will be displayed inside the label
lbl_msg.Text = "Thank you, your mail has been sent successfully.";
}
catch
{
lbl_msg.Text = "Please wait..";
sendmail();
}
}
protected void btnsend_Click(object sender, EventArgs e)
{
sendmail();
}