【问题标题】:How to send an Email in asp.net using c#如何使用 c# 在 asp.net 中发送电子邮件
【发布时间】:2015-03-29 06:30:48
【问题描述】:

这是我的代码:

   protected void BtnSubmit_Click(object sender, EventArgs e)
    { 
        MailMessage msg = new MailMessage();
        msg.From = new MailAddress("Kamal.s.buqlieh@hotmail.com","Kamal");
        msg.To.Add(TxtEmailPass.Text);
        msg.Subject = "Forget Password!";
        msg.Body = "your password is:";
        SmtpClient mySmtpClient = new SmtpClient();
        mySmtpClient.Host = "www.Hotmail.com";
        NetworkCredential nc = new NetworkCredential();
        nc.UserName = "Kamal.s.buqlieh@hotmail.com";
        nc.Password = "";
        mySmtpClient.UseDefaultCredentials = true;
        mySmtpClient.Credentials = nc;
        mySmtpClient.Port = 587;
        mySmtpClient.EnableSsl = true;

        mySmtpClient.Send(msg);


    }

它一直告诉我

“无法建立连接,因为目标机器主动拒绝了它 157.56.198.204:587”

任何人都可以帮助我吗?

【问题讨论】:

  • 恕我直言,要么是防火墙阻止了连接,要么是托管服务的进程没有在该端口上侦听,这可能是因为它根本没有运行,或者因为它正在侦听不同的端口港口。

标签: c# asp.net email


【解决方案1】:

您的主机地址错误。您使用过“www.Hotmail.com”。

mySmtpClient.Host = "www.Hotmail.com";

为您的 Hotmail 帐户尝试以下 SMTP 设置:

  • Hotmail SMTP 服务器名称: smtp.live.com

  • Hotmail SMTP 端口: 25 或 465

【讨论】:

    【解决方案2】:

    如果您使用 Microsoft Outlook 和 Outlook Connector,您可以像定义任何常规 POP3 电子邮件帐户一样定义您的 Hotmail 帐户:

    Hotmail Incoming Mail Server (POP3) - pop3.live.com (logon using Secure Password Authentification - SPA, mail server port: 995)
    
    Hotmail Outgoing Mail Server (SMTP) - smtp.live.com (TLS enabled, port 587)
    

    Incoming and Outgoing Mail Server Settings for Hotmail, Yahoo! Mail, GMail, MSN, AOL and more

    【讨论】:

      猜你喜欢
      • 2013-08-22
      • 2017-08-13
      • 2011-11-21
      • 2012-07-27
      • 1970-01-01
      • 2011-05-24
      • 2012-01-10
      相关资源
      最近更新 更多