【问题标题】:Sending email code through asp.net. Not able to resolve the error通过 asp.net 发送电子邮件代码。无法解决错误
【发布时间】:2013-11-28 12:02:22
【问题描述】:

我正在使用此代码从 iis 服务器部署的应用程序从 gmail 发送电子邮件。 我不断收到无法连接到远程服务器的消息。

请帮忙解决这个问题--

    protected void SendMail()
    {
        MailMessage msg = new MailMessage();
        System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient();
        try
        {
            msg.Subject = "download complete";
            msg.Body = "download is completed";
            msg.From = new MailAddress("xxx@gmail.com");
            msg.To.Add("yyy@gmail.com");
            msg.IsBodyHtml = true;
            client.Host = "smtp.gmail.com";
            System.Net.NetworkCredential basicauthenticationinfo = new System.Net.NetworkCredential("xxx@gmail.com", "xxx");
            client.Port = int.Parse("587");
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            client.Credentials = basicauthenticationinfo;
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Send(msg);
        }
        catch (Exception ex)
        {
            TextBox1.Text = ex.Message;
        }
    }

【问题讨论】:

    标签: asp.net smtp smtpclient


    【解决方案1】:

    首先,您应该能够在该端口 (587) 上 telnet hostname(smtp.gmail.com)。 如果您只能这样做,您就可以从您的应用程序发送邮件。

    启动命令提示符并检查上述命令

    telnet smtp.gmail.com 587
    

    如果你遇到这样的错误Connecting To smtp.gmail.com...Could not open connection to the host, on port 58 7: Connect failed

    这意味着您无法连接到主机服务器。所以你不能使用那个 smtp 发送邮件。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-30
      • 1970-01-01
      • 2013-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多