Basically I have an MVC 3 form which sends a mail to my inbox when someone leaves a message on my site.
For some reason it throws an SmtpException with the message: “Failure sending mail.”
[HttpPost]
public ActionResult Contact(string name, string email, string message)
{
string From = "contactform@******.com";
string To = "info@******.com";
string Subject = name;
string Body = name + " wrote:<br/><br/>" + message;
System.Net.Mail.MailMessage Email = new System.Net.Mail.MailMessage(From, To, Subject, Body);
System.Net.Mail.SmtpClient SMPTobj = new System.Net.Mail.SmtpClient("smtp.**********.net");
SMPTobj.EnableSsl = false;
SMPTobj.Credentials = new System.Net.NetworkCredential("info@*******.com", "*******");
try
{
SMPTobj.Send(Email);
}
catch (Exception ex)
{
Debug.WriteLine(ex.Message);
throw new Exception();
}
return View();
}
Could this be something to do with testing it locally rather than testing it on a server?
Do you need to set the SmtpClient.Port to your Host email port?