我已經建立了一個測試電子郵件的形式提交,並繼續得到以下錯誤消息,不管我有多少種方法嘗試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);
}
}
}
我曾嘗試多種方法和像我正在阻止防病毒/防火牆,感謝在我看來。
你有在本地主機上運行的郵件服務器嗎?這與代碼無關。郵件服務器(127.0.0.1)不允許連接。 – David