I have a problem sending an email from an html form, I have my credentials for sending, the problem is that when I get to the "smtp.send (mail) part"; an exception is generated, and the error message is empty, that is the reason why I do not identify what I am doing wrong.
I hope someone can support me. Greetings and thanks.
Controller
[HttpPost]
public ActionResult EnviarCorreo(String de, String mensaje)
{//, HttpPostedFileBase fichero, String asunto,
try
{
MailMessage correo = new MailMessage();
// correo.From = new MailAddress(de);
correo.From = new MailAddress("[email protected]");
correo.To.Add(new MailAddress("[email protected]"));
correo.Subject = "Mensaje de ayuda";
correo.Body = mensaje;
correo.IsBodyHtml = true;
correo.Priority = MailPriority.Normal;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 25;
smtp.EnableSsl = true;
smtp.UseDefaultCredentials = false;
string CuentaCorreo = "[email protected]";
string PasswordCorreo = "micontra";
smtp.Credentials = new System.Net.NetworkCredential(CuentaCorreo, PasswordCorreo);
smtp.Send(correo);
correo.Dispose();
return Json(new { Result = "OK", mensaje = "Mensaje enviado correctamente" });
}
catch(Exception ex)
{
return Json(new { Result = "ERROR", mensaje = ex.Message });
}
}