I am trying the send email code in asp.net mvc but I keep getting the error {"Failure sending mail."} I have referred to many of the questions asked here and tried out the suggested sollutions but still got the same error. Where am I going wrong?
Here is my code:
private static void SendEmailWithErrors(string result)
{
SmtpClient smtpclient = new SmtpClient();
MailMessage message = new MailMessage();
try
{
MailAddress fromAddress = new MailAddress("email address");
smtpclient.Host = "smtp.gmail.com";
smtpclient.Port = 587;
smtpclient.UseDefaultCredentials = true;
smtpclient.EnableSsl = true;
smtpclient.Credentials = new System.Net.NetworkCredential("email address", "password");
message.From = fromAddress;
message.To.Add("email address");
message.Subject = "Exception raised";
message.IsBodyHtml = false;
message.Body = result;
smtpclient.Send(message);
}
catch(Exception ex)
{
}
}