1. Create a MailHelper class.
public class MailHelper
{
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress(from);
mMailMessage.To.Add(new MailAddress(to));
if (!(string.IsNullOrEmpty(bcc)))
{
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
if (string.IsNullOrEmpty(cc))
{
mMailMessage.CC.Add(new MailAddress(cc));
}
mMailMessage.Subject = subject;
mMailMessage.Body = body;
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient ss = new SmtpClient();
//ss.EnableSsl = true;
ss.Timeout = 10000;
ss.DeliveryMethod = SmtpDeliveryMethod.Network;
mMailMessage.BodyEncoding = UTF8Encoding.UTF8;
mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
ss.Send(mMailMessage);
}
2. Add the following smtp configuration in Web.config file.
public class MailHelper
{
public static void SendMailMessage(string from, string to, string bcc, string cc, string subject, string body)
{
MailMessage mMailMessage = new MailMessage();
mMailMessage.From = new MailAddress(from);
mMailMessage.To.Add(new MailAddress(to));
if (!(string.IsNullOrEmpty(bcc)))
{
mMailMessage.Bcc.Add(new MailAddress(bcc));
}
if (string.IsNullOrEmpty(cc))
{
mMailMessage.CC.Add(new MailAddress(cc));
}
mMailMessage.Subject = subject;
mMailMessage.Body = body;
mMailMessage.IsBodyHtml = true;
mMailMessage.Priority = MailPriority.Normal;
// Instantiate a new instance of SmtpClient
SmtpClient ss = new SmtpClient();
//ss.EnableSsl = true;
ss.Timeout = 10000;
ss.DeliveryMethod = SmtpDeliveryMethod.Network;
mMailMessage.BodyEncoding = UTF8Encoding.UTF8;
mMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
ss.Send(mMailMessage);
}
2. Add the following smtp configuration in Web.config file.