2014-06-10 41 views
0

我已經建立了一個測試電子郵件的形式提交,並繼續得到以下錯誤消息,不管我有多少種方法嘗試System.Net.Mail.SmtpException:發送郵件失敗。無連接可以作出,因爲目標機器積極地拒絕它127.0.0.1:25

系統.Net.Mail.SmtpException:發送郵件失敗。 ---> System.Net.WebException:無法連接到遠程服務器---> System.Net.Sockets.SocketException:由於目標機器主動拒絕它,因此無法建立連接127.0.0.1:25在System.Net .Socket.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)在System.Net.ServicePoint.ConnectSocketInternal(布爾connectFailure,套接字s4,套接字s6,套接字&套接字,IP地址&地址,ConnectSocketState狀態,IAsyncResult asyncResult,例外&異常) - - 在System.Net.ServicePoint.GetConnection處的內部異常堆棧跟蹤結束(PooledStream PooledStream,Object owner,Boolean async,IPAddress & address,Socket & abortSocket,Socket & abortSocket6)at System.Net.PooledStream.Activate( Object owningObject,Boolean async,GeneralAsyncDelegate asyncCallback) System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)上的System.Net.PooledStream.Activate(Object owningObject,GeneralAsyncDelegate asyncCallback)位於System.Net.ConnectionPool.GetConnection(Object owningObject,GeneralAsyncDelegate asyncCallback,Int32 creationTimeout)。 System.Net.Mail.SmtpClient.GetConnection()處的System.Net.Mail.SmtpClient.Send(MailMessage消息)處的Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)---內部異常堆棧跟蹤結束--- at System.Net.Mail.SmtpClient.Send(MailMessage消息)位於c:\ Users \ jack \ Documents \ Visual Studio 2013 \ WebSites \ firstarPrecision \ frmQuote.aspx.cs中的frmQuote.btnSubmit_Click(Object sender,EventArgs e):第28行

如果需要的話,這裏是我用來提交表格的C#代碼

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net.Mail; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

public partial class frmQuote : System.Web.UI.Page 
{ 
    protected void Page_Load(object sender, EventArgs e) 
    { 

    } 
    protected void btnSubmit_Click(object sender, EventArgs e) 
    { 
     try 
     { 
      using (MailMessage message = new MailMessage()) 
      { 
       message.From = new MailAddress(txtEmail.Text.ToString()); 
       message.To.Add(new MailAddress("[email protected]")); 
       //message.CC.Add(new MailAddress("[email protected]")); 
       message.Subject = "Quote request from " + txtCompanyName.Text.ToString(); 
       message.Body = txtContact.Text.ToString(); 
       SmtpClient client = new SmtpClient(); 
       client.Host = "127.0.0.1"; 
       client.Send(message); 
      } 
     } 
     catch(Exception ex) { 
      Response.Write(ex); 
     } 
    } 
} 

我曾嘗試多種方法和像我正在阻止防病毒/防火牆,感謝在我看來。

+1

你有在本地主機上運行的郵件服務器嗎?這與代碼無關。郵件服務器(127.0.0.1)不允許連接。 – David

回答

1

你是triyng發送它通過本地計算機上的SMTP(127.0.0.1),我認爲它沒有運行smtp服務器。

如果您需要的設施,以方便地通過SMTP我建議mandrill smtp,很容易和自由地使用發送電子郵件,

+0

這就是當你累了XD時會發生什麼。感謝我給了這個mandrill一個嘗試,通常我只是使用Gmail帳戶作爲SMTP服務器,但這可能是一個更好的選擇,謝謝。 –

+0

正如我看到你的代碼,我認爲你使用的是Gmail,我有很多麻煩與Gmail作爲smtp(所有這些因爲發送通過相同的帳戶,但從不同的地方,該帳戶每次鎖定),所以mandrill可以幫助你如果你遇到同樣的情況。 – Gusman

0

首先,正如其他人所說,你需要運行在一臺郵件服務器本地主機爲此工作。端口25是SMTP的默認郵件,但這並不意味着郵件服務器處於待命狀態。您可以使用免費的電子郵件地址確保電子郵件真正獲得交付,並且您需要的唯一更改是添加您的帳戶憑證(請參閱this tutorial for reference)。有關端口信息,請查看電子郵件提供商有關設置電子郵件客戶端的說明,這些客戶端應在任何電子郵件提供商的「設置」菜單中提供。

相關問題