using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.Net.Security;
using System.Web;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using System.Threading.Tasks;
using HELP;
using System.Web.Configuration;
public bool SendingMail(string strBody = "", string strToMail = "", string subject = "Forgot Password Details.")
{
try
{
System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
SmtpClient smtp = new SmtpClient();
smtp.Host = WebConfigurationManager.AppSettings["SMTP_Host"].ToString();
smtp.EnableSsl = true;
NetworkCredential NetworkCred = new NetworkCredential();
NetworkCred.UserName = WebConfigurationManager.AppSettings["SMTP_UserName"].ToString();
NetworkCred.Password = WebConfigurationManager.AppSettings["SMTP_Password"].ToString();
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = Convert.ToInt32(WebConfigurationManager.AppSettings["SMTP_Port"].ToString());
msg.To.Add(strToMail);
msg.From = new MailAddress(WebConfigurationManager.AppSettings["FromEmail"].ToString());
msg.Subject = subject;
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; };
msg.Body = strBody;
msg.IsBodyHtml = true;
smtp.Send(msg);
return true;
}
catch (SmtpException ex)
{
return false;
}
}
Call from Front end this method in button click.