[英]System.Net.Mail.SmtpException: Failure sending mail. No connection could be made because the target machine actively refused it 127.0.0.1:25
I have set up a test email form submission and continue to get the following error message no matter how many ways i try 我已经设置了测试电子邮件表单提交,无论我尝试多少方法,都继续收到以下错误消息
System.Net.Mail.SmtpException: Failure sending mail. System.Net.Mail.SmtpException:发送邮件失败。 ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1: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, 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) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback ---> 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) , 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) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at frmQuote.btnSubmit_Click(Object sender, EventArgs e) in c:\\Users\\jack\\Documents\\Visual Studio 2013\\WebSites\\firstarPrecision\\frmQuote.aspx.cs:line 28 ,位于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
If it is needed here is the C# code that i am using to submit the form 如果需要,这里是我用来提交表单的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);
}
}
}
I have tried several ways and it seems to me like i am being blocked by an antivirus/firewall, thanks. 我已经尝试了几种方法,在我看来,我好像被防病毒/防火墙阻止了,谢谢。
You are triyng to send it through an SMTP on your local machine (127.0.0.1) which I assume does not have an smtp server running. 您正在尝试通过本地计算机(127.0.0.1)上的SMTP发送该邮件,我认为该计算机没有运行SMTP服务器。
If you need a facility to send e-mails easily through SMTP I recommend mandrill smtp , very easy and free to use, 如果您需要通过SMTP轻松发送电子邮件的工具,建议您使用mandrill smtp ,它非常容易且免费使用,
First and foremost, as mentioned by others, you need to be running a mail server on localhost for this to work. 首先,正如其他人提到的那样,您需要在localhost上运行邮件服务器才能正常工作。 Port 25 is the default post for SMTP but that doesn't mean there's a mail server standing by. 端口25是SMTP的默认帖子,但这并不意味着有邮件服务器在等待。 You can use a free e-mail address to make sure the e-mail really gets delivered and the only change you'd need is to add your account credentials (see this tutorial for reference ). 您可以使用免费的电子邮件地址来确保电子邮件确实得到发送,并且唯一需要做的更改就是添加帐户凭据(请参阅本教程作为参考 )。 For the port information, check the e-mail provider's instructions for setting up e-mail clients, which should be available in the Settings menu of just about any e-mail provider. 有关端口信息,请查看电子邮件提供商的设置电子邮件客户端的说明,几乎所有电子邮件提供商的“设置”菜单中都应提供这些说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.