this below code works perfectly; try this one
using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net.Mail;
using System.Security.Permissions;
public class SendMail
{
string to;
string subject;
string message;
string frm;
public SendMail(string to, string subject, string message, string frm)
{
this.to = to;
this.subject = subject;
this.message = message;
this.frm = frm;
}
public bool Send()
{
string user = ConfigurationManager.AppSettings["username"].ToString();
string password = ConfigurationManager.AppSettings["password"].ToString();
SmtpClient SmtpServer = new SmtpClient();
SmtpServer.Credentials = new System.Net.NetworkCredential(user, password);
SmtpServer.Port = 587;
SmtpServer.Host = "smtp.gmail.com";
SmtpServer.EnableSsl = true;
MailMessage mail = new MailMessage();
try
{
mail.From = new MailAddress(user, "Subject", System.Text.Encoding.UTF8);
mail.To.Add(new MailAddress(to));
mail.Subject = subject;
mail.Body = message;
mail.IsBodyHtml = true;
mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
mail.ReplyTo = new MailAddress(frm);
SmtpServer.Send(mail);
}
catch (Exception err)
{
return false;
}
return true;
}
}