ASP.NET - 发送电子邮件时出错

ASP.NET - Error sending email Messages

我检查了其他问题,并且能够解决我的代码中的一些错误,但是 smtp.Credentials = nc; 抛出异常,其中 nc 是我的网络凭据,请求操作已中止MFE 代理,SMTP 服务器不可用

请提供任何帮助,我们将不胜感激。下面是我的代码:

           MailMessage msg = new MailMessage();
            msg.From = new MailAddress("fromemail");
            msg.To.Add("toemail");
            msg.Subject = "Contact Us";
            msg.Body = cname.Text + "sent me this message" + cmessage.Text + "with this email, " + email.Text;
            msg.IsBodyHtml = true;

            SmtpClient smtp = new SmtpClient();
            smtp.Host = "smtp.gmail.com";
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
            smtp.EnableSsl = false;
            smtp.UseDefaultCredentials = false;
            smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
            NetworkCredential nc = new NetworkCredential();
            nc.UserName = "fromemail";
            nc.Password = "fromemailpwd";
            smtp.Credentials = nc;
            smtp.Port = 587;
            smtp.Send(msg);
            sPanel.Visible = true;
            lblSuccess.Text = "Success! Thanks for contacting us, we will get back to you soon.";

我将 smtp.Credentials = nc 更改为 smtp.Credentials = new NetworkCredentials("fromemail", "fromemailpwd"); 现在,正是这一行 smtp.Send(msg) 引发了异常。

我无法收到与您看到的相同的错误消息,但请查看此答案:Request action aborted on MFE proxy, SMTP server is not available

不过,我知道 Gmail 需要 EnableSSL = True