using System.Net.Mail;

Mail mail = new Mail();
MailMessage message = new MailMessage();
message.To.Add(email);
message.From = new MailAddress("userid@gmail.com");
message.Subject = "Test mail";
message.IsBodyHtml = false;
message.Body = "This is a test message.";

public bool sendMail(MailMessage message)
 {
            SmtpClient smtp = new SmtpClient();
            bool result = true;

            try
            {
                smtp.Host = "smtp.gmail.com";
                smtp.Port = 587;
                smtp.EnableSsl = true;
                smtp.UseDefaultCredentials = true;
                smtp.Credentials = new System.Net.NetworkCredential("userid@gmail.com", "password");
                smtp.Send(message);
            }
            catch (Exception exp)
            {
                result = false;
            }

            return result;
}


+ Recent posts