Gmail Error :The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required

后端 未结 25 2847
悲&欢浪女
悲&欢浪女 2020-11-22 02:12

I am using following code to send email. The Code works correctly in my local Machine. But on Production server i am getting the error message

var fromAddres         


        
25条回答
  •  执笔经年
    2020-11-22 02:52

    I had the same problem for an application deployed to Microsoft Azure.

    SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.

    First I approved all unknown devices (some ip-addresses originating from Ireland) on the following page (signed in as the gmail user): https://security.google.com/settings/u/1/security/secureaccount

    I used the following settings for the client:

    var client = new SmtpClient("smtp.gmail.com");
    client.Port = 587;
    client.EnableSsl = true;
    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential("my_user_name@gmail.com", "my_password"); 
    

    It started working only after I set the following property on the smtp-client:

    client.TargetName = "STARTTLS/smtp.gmail.com";
    

提交回复
热议问题