Here is the code in the controller:
[HttpPost, ValidateInput(true)]
public ActionResult Contact(ContactForm model)
{
if (!ModelState.IsValid)
{
return Json("error");
}
else
{
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.UserName =
WebMail.Password =
WebMail.EnableSsl = true;
string message = model.Name + " " + model.Telephone + " " + model.Email + " " + model.Address + " " + model.City + " " + model.ZipCode;
try
{
WebMail.Send("example@example.com", "philaslim.com/info email", message, model.Email);
return Json("thanks");
}
catch (Exception ex)
{
return Json(ex.Message.ToString());
}
}
As I said, this happens not only on the production server. The returned exception message is "Sending mail with an error." Any ideas?
EDIT: InnerException:
System.Net.WebException: --- > System.Net.Sockets.SocketException: , 74.125.53.108:25 System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket & socket, IPAddress & address, ConnectSocketState, IAyncResult asyncResult, - Int32, ) --- --- System.Net.ServicePoint.GetConnection(PooledStream PooledStream, , , IP- , Socket & abortSocket, Socket & abortSocket6, Int32) System.Net.PooledStream.Activate(Object owningObject, , Int32--, GeneralAsyncDelegate asyncCallback) System.Ne t.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) System.Net.Mail.SmtpClient.GetConnection() System.Net.Mail.SmtpClient.Send( MailMessage)