How to set username and password for SmtpClient object in .NET?

前端 未结 4 1900
抹茶落季
抹茶落季 2020-12-01 00:07

I see different versions of the constructor, one uses info from web.config, one specifies the host, and one the host and port. But how do I set the username and password to

4条回答
  •  清歌不尽
    2020-12-01 00:21

    Use NetworkCredential

    Yep, just add these two lines to your code.

    var credentials = new System.Net.NetworkCredential("username", "password");
    
    client.Credentials = credentials;
    

提交回复
热议问题