public static string SendMail(string from, string to, string subject, string body)
{
MailMessage mailMessage = new MailMessage();
mailMessage.From = new MailAddress(from);
mailMessage.To.Add(to);
mailMessage.Subject = subject;
mailMessage.IsBodyHtml = true;
mailMessage.BodyEncoding = Encoding.UTF8;
mailMessage.Body = body;
mailMessage.Priority = MailPriority.Normal;
SmtpClient client = new SmtpClient();
client.Credentials = new NetworkCredential("mygmailaddress", "password");
client.Port = 587;
client.Host = "smtp.gmail.com";
client.EnableSsl = true;
MailMessage message = mailMessage;
try
{
client.Send(message);
return "true";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
This Code Works fine....