2011-12-23 43 views
5

工程確定這裏是代碼:從谷歌發送電子郵件失敗生產服務器上,但在控制器從本地主機

[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()); 
       } 

      } 

正如我所說的,只在生產服務器發生故障。返回的異常消息是「發送郵件失敗。」。有任何想法嗎?

編輯:的InnerException:

System.Net.WebException:無法連接到遠程服務器---> System.Net.Sockets.SocketException:A連接嘗試失敗,因爲連接的方沒有正確響應後一段時間或建立的連接失敗,因爲連接的主機未能在System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress))上響應74.125.53.108:25。套接字s4,套接字s6,套接字&套接字,IP地址&地址,ConnectSocketState狀態,IAsyncResult asyncResult,Int32超時,例外&例外)--- End of end e xception堆棧跟蹤---在System.Net.ServicePoint.GetConnection(PooledStream PooledStream,對象所有者,布爾異步,IP地址&地址,套接字& abortSocket,套接字& abortSocket6,Int32超時)在System.Net.PooledStream.Activate(Object owningObject ,System.Net.Mail上的System.Net.ConnectionPool.GetConnection(Object owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)上的System.Net.PooledStream.Activate(Object owningObject,GeneralAsyncDelegate asyncCallback),布爾異步,Int32超時,GeneralAsyncDelegate asyncCallback)。 System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)System.Net.Mail.SmtpClient.GetConnection()上的SmtpConnection.GetConnection(ServicePoint servicePoint)在System.Net.Mail.SmtpClient.Send(MailMessage消息)

+1

InnerException中有什麼嗎? – Lester 2011-12-23 01:21:12

+0

請參閱編輯 – 2011-12-23 01:24:57

+0

您的生產服務器是否需要代理才能訪問Internet? – hawkke 2011-12-23 01:29:12

回答

6

您的外發SMTP端口(25,587)可能在您的服務器上關閉,請檢查您的防火牆設置。

+0

我正在使用godaddy。我想要給他們打電話。 – 2011-12-23 01:32:06

+0

你救了我的命 - 這是在幾個小時內!非常感謝! – 2011-12-23 02:15:52

相關問題