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

后端 未结 7 2133
萌比男神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("<the section name>");
    var credentials == smtpSection.Network;
    
    0 讨论(0)
提交回复
热议问题