Here is the code in controller:
[HttpPost, ValidateInput(true)]
public ActionResult Contact(ContactForm model)
{
if (!ModelState.IsValid)
{
return Json("error");
}
else
{
WebMail.SmtpServer = "smtp.gmail.com";
WebMail.UserName = //email here
WebMail.Password = //password here
WebMail.EnableSsl = true;
string message = model.Name + " " + model.Telephone + " " + model.Email + " " + model.Address + " " + model.City + " " + model.ZipCode;
try
{
WebMail.Send("[email protected]", "philaslim.com/info email", message, model.Email);
return Json("thanks");
}
catch (Exception ex)
{
return Json(ex.Message.ToString());
}
}
As I said it fails only on production server. The returned exception message is "Failure sending mail.". Any ideas?
EDIT: InnerException:
System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.53.108:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message)