SMTP 服务器验证错误

SMTP Server Authentication Error

我正在开发一个应用程序,如果调用了全局线程异常,我想将崩溃报告发送到电子邮件。但是,每次我尝试发送这封电子邮件时,都会收到错误消息

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. <-- the error message ends here which seems weird.

我的异常事件处理程序如下所示:

private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
    {
        MailAddress fromAddress = new MailAddress("user@domain.com", "Mary");
        MailAddress toAddress = new MailAddress("user@domain.com", "Sam");
        const string fromPassword = "password";
        const string subject = "Exception Report";
        Exception exception = e.ExceptionObject as Exception;
        string body = exception.Message + "\n" + exception.Data + "\n" + exception.StackTrace + "\n" + exception.Source;

        var smtp = new SmtpClient
        {
            Host = "smtp.gmail.com",
            Port = 587,
            EnableSsl = true,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
        };
        using (MailMessage message = new MailMessage(fromAddress, toAddress)
        {
            Subject = subject,
            Body = body
        })
        {
            try
            { 
                smtp.Send(message);
            }
           catch(Exception err)
            {
                Console.WriteLine("Could not send e-mail. Exception caught: " + err);
            }
        }
    }

有谁知道为什么我会收到此服务器身份验证错误?

Google 可能会阻止某些不使用现代安全标准的应用程序或设备的登录尝试。由于这些应用和设备更容易被侵入,阻止它们有助于确保您的帐户更安全。

一些不支持最新安全标准的应用示例包括:

  • iPhone 或 iPad iOS 6 岁或以下
  • 的邮件应用程序
  • 您的 Windows phone 8.1 版本之前的邮件应用程序
  • 一些桌面邮件客户端,例如 Microsoft Outlook 和 Mozilla Thunderbird

因此,您必须在您的 google 帐户中启用 低安全性 Sign-In

登录 google 帐户后,转到:

https://www.google.com/settings/security/lesssecureapps