C# System.Net.Mail.SmtpException:发送邮件失败。无法建立连接,因为目标计算机主动拒绝127.0.0.1:25

C# System.Net.Mail.SmtpException:发送邮件失败。无法建立连接,因为目标计算机主动拒绝127.0.0.1:25,c#,asp.net,forms,email,exception,C#,Asp.net,Forms,Email,Exception,我已经设置了一个测试电子邮件表单提交,并继续得到以下错误消息,无论我如何尝试 System.Net.Mail.SmtpException:发送邮件失败。-->System.Net.WebException:无法连接到远程服务器-->System.Net.Sockets.SocketException:无法建立连接,因为目标计算机在System.Net.ServicePoint.ConnectSocketInternal的System.Net.Sockets.Socket.DoConnect(En

我已经设置了一个测试电子邮件表单提交,并继续得到以下错误消息,无论我如何尝试

System.Net.Mail.SmtpException:发送邮件失败。-->System.Net.WebException:无法连接到远程服务器-->System.Net.Sockets.SocketException:无法建立连接,因为目标计算机在System.Net.ServicePoint.ConnectSocketInternal的System.Net.Sockets.Socket.DoConnect(EndPoint EndPoint endPointSnapshot,SocketAddress SocketAddress SocketAddress)主动拒绝了它127.0.0.1:25(布尔连接失败、套接字s4、套接字s6、套接字和套接字、IPAddress和address、ConnectSocketState状态、IAsyncResult asyncResult、异常和异常)----内部异常堆栈跟踪的结束---位于System.Net.ServicePoint.GetConnection(PooledStream PooledStream、对象所有者、布尔异步、IPAddress&address、Socket&abortSocket、Socket&abortSocket6)在System.Net.PooledStream.Activate(对象所有者对象、布尔异步、GeneralAsyncDelegate异步回调)在System.Net.PooledStream.Activate(对象所有者对象、GeneralAsyncDelegate异步回调)在System.Net.Mail.SmtpConnection.GetConnection(ServicePoint ServicePoint)的System.Net.Mail.SmtpTransport.GetConnection(ServicePoint ServicePoint)的System.Net.Mail.SmtpClient.GetConnection(ServicePoint ServicePoint)的System.Net.Mail.SmtpTransport.GetConnection(ServicePoint ServicePoint ServicePoint)的System.Net.Mail.SmtpClient.GetConnection()中在System.Net.Mail.SmtpClient.Send(MailMessage message)-内部异常堆栈跟踪结束-在System.Net.Mail.SmtpClient.Send(MailMessage message)处frmQuote.btnSubmit\u单击c:\Users\jack\Documents\Visual Studio 2013\WebSites\firstarPrecision\frmQuote.aspx.cs中的(对象发送者,事件参数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("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轻松发送电子邮件的工具,我建议您使用它,非常简单且免费,

首先,正如其他人所提到的,您需要在本地主机上运行邮件服务器才能正常工作。端口25是SMTP的默认post,但这并不意味着有邮件服务器随时待命。您可以使用免费电子邮件地址要确保电子邮件真正送达,您需要做的唯一更改是添加您的帐户凭据(请参阅)。有关端口信息,请查看电子邮件提供商关于设置电子邮件客户端的说明,该说明应位于几乎所有电子邮件提供商的“设置”菜单中。

您是否在本地主机上运行邮件服务器?这与代码无关。邮件服务器(127.0.0.1)不允许连接。这是当你累了XD时会发生的情况。谢谢我会尝试一下mandrill,通常我只是使用Gmail帐户作为SMTP服务器,但这可能是一个更好的选择,谢谢。当我看到你的代码时,我以为你在使用Gmail,我在使用Gmail作为SMTP时遇到了很多麻烦(所有这些都是因为通过同一个帐户但从不同的地方发送,每次帐户都被锁定)因此,如果遇到相同的情况,mandrill可以帮助您。