繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM