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

前端 未结 4 1891
抹茶落季
抹茶落季 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

    The SmtpClient can be used by code:

    SmtpClient mailer = new SmtpClient();
    mailer.Host = "mail.youroutgoingsmtpserver.com";
    mailer.Credentials = new System.Net.NetworkCredential("yourusername", "yourpassword");
    

提交回复
热议问题