The SMTP server requires a secure connection or the client was not authenticated

后端 未结 3 573
暗喜
暗喜 2020-12-09 15:23

I am getting this error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTL         


        
相关标签:
3条回答
  • 2020-12-09 15:48

    This worked for me:

    1. Need to turn on "Access for less secure apps" on google account(From Email).
    2. Set smtpclient.UseDefaultCredentials = false;
    3. Set smtpclient.EnableSsl = true;

          MailMessage mail = new MailMessage("FromEmail_Address", "ToEmail_Address");
          SmtpClient smtpclient = new SmtpClient();
          smtpclient.Port = 587;
          smtpclient.DeliveryMethod = SmtpDeliveryMethod.Network;
          smtpclient.UseDefaultCredentials = false;
          smtpclient.Host = "smtp.gmail.com";
          smtpclient.UseDefaultCredentials = false;
          mail.Subject = "Email Subject";
          mail.Body = "Content of the email";
          smtpclient.EnableSsl = true;
          smtpclient.Credentials = new System.Net.NetworkCredential()
          {
              UserName = "FromEmail_Address",
              Password = "password of the email"
          };
          client.Send(mail);
      
    0 讨论(0)
  • 2020-12-09 15:57

    Actually you can handle this in your web.config file by adding enableSsl="true". This worked for me and I didn't need to do anything in code.

    e.g.

    <network host="smtp.gmail.com" enableSsl="true" ... />
    
    0 讨论(0)
  • 2020-12-09 16:02

    Try setting the EnableSsl property to true:

    smtpClient.EnableSsl = true;
    

    AFAIK this property can only be set in code and cannot be specified in the config file.

    0 讨论(0)
提交回复
热议问题