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

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

This is my web.config mail settings:


    
      

        
7条回答
  •  猫巷女王i
    2021-01-31 01:56

                //You can access the network credentials in the following way.
                //Read the SmtpClient section from the config file    
                var smtp = new System.Net.Mail.SmtpClient();
                //Cast the newtwork credentials in to the NetworkCredential class and use it .
                var credential = (System.Net.NetworkCredential)smtp.Credentials;
                string strHost = smtp.Host;
                int port = smtp.Port;
                string strUserName = credential.UserName;
                string strFromPass = credential.Password;
    

提交回复
热议问题