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

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

This is my web.config mail settings:


    
      

        
7条回答
  •  感情败类
    2021-01-31 02:21

    By using the configuration, the following line:

    var smtp = new System.Net.Mail.SmtpClient();
    

    Will use the configured values - you don't need to access and assign them again.


    As for the null values - you are trying accessing the configuration values incorrectly. You are just creating an empty SmtpSection instead of reading it from configuration.

    var smtpSection = (SmtpSection)ConfigurationManager.GetSection("");
    var credentials == smtpSection.Network;
    

提交回复
热议问题