这是我的web.config
邮件设置:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="smthg@smthg.net">
<network defaultCredentials="true" host="localhost" port="587" userName="smthg@smthg.net" password="123456"/>
</smtp>
</mailSettings>
</system.net>
这就是我尝试从中读取值的方法web.config
var smtp = new System.Net.Mail.SmtpClient();
var credential = new System.Net.Configuration.SmtpSection().Network;
string strHost = smtp.Host;
int port = smtp.Port;
string strUserName = credential.UserName;
string strFromPass = credential.Password;
但凭据始终为空。我如何访问这些值?