'SMTP服务器需要安全的连接,或者客户端未通过身份验证。服务器响应为:5.7.0需要身份验证

时间:2020-04-26 08:34:22

标签: visual-studio winforms

System.Net.Mail.SmtpException:'SMTP服务器需要安全连接,或者客户端未通过身份验证。服务器响应为:5.7.0需要身份验证。

enter image description here

        using (SqlConnection con = new SqlConnection(ApplicationSettings.ConnectionString()))
        {
            con.Open();
            //try
            //{
                SqlCommand cmd = new SqlCommand("SELECT [Email Address] FROM [Staff] WHERE [Access Level]='Manager'", con);
                SqlDataReader sdr = cmd.ExecuteReader();
                if (sdr.Read())
                {

                    string emailaddress = Convert.ToString(sdr["Email Address"]);


                    MailMessage mail = new MailMessage();
                    SmtpClient smtpServer = new SmtpClient("smtp.gmail.com");
                    mail.From = new MailAddress("possystemmahdealjamil@gmail.com");
                    mail.To.Add(emailaddress);
                    mail.Subject = "Todays POS System Reports";
                    mail.Body = "Todays shift is closed at"+DateTime.Now.ToString();

                    smtpServer.Port = 587;
                    smtpServer.Credentials = new [enter image description here][1]System.Net.NetworkCredential("possystemmahdealjamil@gmail.com", @"###########");
                    smtpServer.EnableSsl = true;
                    smtpServer.Send(mail);

                    MessageBox.Show("Mail is Send Successfully ", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message, "open shift failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            //}
            //finally
            //{
            //    con.Close();
            //}
        }

2 个答案:

答案 0 :(得分:1)

我的问题解决了,出现了安全设置问题,为此,我不得不允许我的发件人电子邮件上访问不太安全的应用程序选项

答案 1 :(得分:1)

我也遇到过同样的问题。尽管我已在发件人电子邮件中授予对安全性较低的应用程序的访问权限,但问题仍未解决。经过彻底的搜索和反复试验,我已将发件人电子邮件的密码更改为比以前更强大的新密码。瞧!问题解决了。

真正令人困惑的是,这种较弱密码的错误通常带有代码 5.5.1。像这样: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

如果现有密码不符合电子邮件主机的密码要求,则可能会发生这种情况。但对我来说,错误代码是 5.7.0。