How to read system.net/mailSettings/smtp from Web.config

后端 未结 7 2142
萌比男神i
萌比男神i 2021-01-31 01:16

This is my web.config mail settings:


    
      

        
7条回答
  •  广开言路
    2021-01-31 02:16

    It is not necessary to use the ConfigurationManagerand get the values manually. Simply instantiating an SmtpClient is sufficient.

    SmtpClient client = new SmtpClient();
    

    This is what MSDN says:

    This constructor initializes the Host, Credentials, and Port properties for the new SmtpClient by using the settings in the application or machine configuration files.

    Scott Guthrie wrote a small post on that some time ago.

提交回复
热议问题