Confused with the SmtpClient.UseDefaultCredentials Property

前端 未结 4 1529
后悔当初
后悔当初 2020-12-16 14:30

In my MVC4 application, I\'m using the SmtpClient to send out email via Gmail\'s smtp.gmail.com SMTP server.

I\'ve configured my Web.Config

4条回答
  •  半阙折子戏
    2020-12-16 15:19

    I was getting the same message and it was driving me crazy. After reading this thread I realized that the order mattered on setting my credentials. This worked:

    client.UseDefaultCredentials = false;
    client.Credentials = new NetworkCredential(smtpSettings.Username, smtpSettings.Password);
    

    While this generated the error you describe:

    client.Credentials = new NetworkCredential(smtpSettings.Username, smtpSettings.Password);
    client.UseDefaultCredentials = false;
    

    This is just an FYI to anybody else having the same problem.

提交回复
热议问题