[英]System.Net.Mail.SmtpException: Failure sending mail. Unable to read data from the transport connection
[英]System.Net.Mail.SmtpException: Failure sending mail. No connection could be made because the target machine actively refused it 127.0.0.1:25
我已經設置了測試電子郵件表單提交,無論我嘗試多少方法,都繼續收到以下錯誤消息
System.Net.Mail.SmtpException:發送郵件失敗。 ---> System.Net.WebException:無法連接到遠程服務器---> System.Net.Sockets.SocketException:無法建立連接,因為目標計算機在System.Net上主動拒絕了127.0.0.1:25 .Sockets.Socket.DoConnect(EndPoint endPointSnapshot,SocketAddress socketAddress)位於System.Net.ServicePoint.ConnectSocketInternal(布爾值connectFailure,Socket s4,Socket s6,套接字和套接字,IP地址和地址,ConnectSocketState狀態,IAsyncResult,asyncResult,異常和異常)---結束內部異常堆棧跟蹤--在System.Net.PooledStream.Activate(Object owneringObject,Boolean async,在System.Net.ServicePoint.GetConnection(PooledStream PooledStream,對象所有者,布爾異步,IPAddress&地址,Socket&abortSocket,Socket&abortSocket6) System.Net.PooledStream.Activate(對象owningObject,GeneralAsyncDelegate asyncCallback)上的GeneralAsyncDelegate asyncCallback)System.Net.ConnectionPool.GetConnection(對象owningObject,GeneralAsyncDelegate asyncCallback) ,位於System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint),位於System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint),位於System.Net.Mail.SmtpClient.GetConnection()處的Int32 creationTimeout) .SmtpClient.Send(MailMessage消息)-內部異常堆棧跟蹤的結尾-在System.Net.Mail.SmtpClient.Send(MailMessage消息)處位於c:\\ Users中frmQuote.btnSubmit_Click(Object sender,EventArgs e) \\ jack \\ Documents \\ Visual Studio 2013 \\ WebSites \\ firstarPrecision \\ frmQuote.aspx.cs:line 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("swdlodonnell@gmail.com"));
//message.CC.Add(new MailAddress("copy@domain.com"));
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)上的SMTP發送該郵件,我認為該計算機沒有運行SMTP服務器。
如果您需要通過SMTP輕松發送電子郵件的工具,建議您使用mandrill smtp ,它非常容易且免費使用,
首先,正如其他人提到的那樣,您需要在localhost上運行郵件服務器才能正常工作。 端口25是SMTP的默認帖子,但這並不意味着有郵件服務器在等待。 您可以使用免費的電子郵件地址來確保電子郵件確實得到發送,並且唯一需要做的更改就是添加帳戶憑據(請參閱本教程作為參考 )。 有關端口信息,請查看電子郵件提供商的設置電子郵件客戶端的說明,幾乎所有電子郵件提供商的“設置”菜單中都應提供這些說明。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.