gpt4 book ai didi

c# - 当我运行这段代码时,它在 (smtp.Send(mm);) 出现错误,我不知道如何解决

转载 作者:太空宇宙 更新时间:2023-11-03 12:23:57 26 4
gpt4 key购买 nike

这段代码在运行时给我带来了一些问题。它不发送消息,它说错误在 smtp.Send(mm);我无法解决它

    if (!string.IsNullOrEmpty(password))
{
System.Net.Mail.MailMessage mm = new System.Net.Mail.MailMessage("eden.elao@gmail.com", Username.Text.Trim());
mm.Subject = "Password Recovery";
mm.Body = string.Format("Hi {0},<br /><br />Your password is {1}.<br /><br />Thank You.", username, password);
mm.IsBodyHtml = true;
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.EnableSsl = true;
System.Net.NetworkCredential NetworkCred = new System.Net.NetworkCredential();
NetworkCred.UserName = "sender@gmail.com";
NetworkCred.Password = "<Password>";
smtp.UseDefaultCredentials = true;
smtp.Credentials = NetworkCred;
smtp.Port = 587;
smtp.Send(mm); // the error is here.
lblMessage.ForeColor = System.Drawing.Color.Green;
lblMessage.Text = "Password has been sent to your email address.";
}
else
{
lblMessage.ForeColor = System.Drawing.Color.Red;
lblMessage.Text = "This email address does not match our records.";
}
}

最佳答案

我相信您遇到了 smtp 服务器的安全问题,我通过在这些行中提供我的真实 gmail 帐户信息使其正常工作:"<Password>"似乎行不通。

  NetworkCred.UserName = "myEmail@gmail.com";
NetworkCred.Password = "myPassword";

并打开我的 gmail 帐户的设置以允许安全性较低的应用程序访问它。

仅供引用,对于其他人来说,这是我更改之前的错误。

Additional information: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at

关于c# - 当我运行这段代码时,它在 (smtp.Send(mm);) 出现错误,我不知道如何解决,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45945738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com