Hola estoy tratando de mandar un mail desde ASP.NET
este es mi metodo
public ActionResult BolsaDeTrabajoContacto(string email_, string body, string nombre, string subject, HttpPostedFileBase files) {
using(DBEnt db = new DBEnt()) {
var cont = db.Contactos.ToList < Contactos > ().Where(u => u.tipo.Equals("mitipo")).FirstOrDefault();
var dest = cont.destino;
string path = "~/Content/Upload/";
try {
MailAddress from = new MailAddress("[email protected]");
MailAddress to = new MailAddress("[email protected]");
MailMessage mail = new MailMessage(from, to);
mail.From = new MailAddress("[email protected]");
//mail.To.Add("[email protected]");
mail.Subject = nombre + " : " + subject;
mail.Body = body;
SmtpClient SmtpServer = new SmtpClient("pw.fs.com.mx", 587);
SmtpServer.Port = 587;
SmtpServer.Credentials = new NetworkCredential("[email protected]", "mi.pass.sh");
SmtpServer.EnableSsl = true;
SmtpServer.UseDefaultCredentials = false;
if (files != null) {
Directory.CreateDirectory(Server.MapPath(path));
string filePath = Server.MapPath(path + files.FileName);
files.SaveAs(filePath);
mail.Attachments.Add(new Attachment(Server.MapPath(path + files.FileName)));
}
ServicePointManager.ServerCertificateValidationCallback = delegate(
object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) {
return true;
};
SmtpServer.Send(mail);
//MessageBox.Show("mail Send");
} catch (Exception ex) {
//MessageBox.Show(ex.ToString());
return Json("Error mandar mail " + ex.ToString());
}
return Json("Exito mandando mail ");
}
}
este es mi error:
"Error mandar mail System.Net.Mail.SmtpFailedRecipientException: El buzón de correo no está disponible. La respuesta del servidor fue: SMTP AUTH is required for message submission on port 587\r\n en System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException& exception)\r\n en System.Net.Mail.SmtpClient.Send(MailMessage message)\r\n en WebFS.Controllers.HomeController.BolsaDeTrabajoContacto(String email_, String body, String nombre, String subject, HttpPostedFileBase files) en C:\Users\EjeDesarrolloCS-162\source\repos\WebFS\WebFS\Controllers\HomeController.cs:línea 555"
pw.fs.com.mx
para el smtp junto a un mail degmail
, el smtp de gmail essmtp.gmail.com