讀system.net/mailSettings/smtp這是我web.config
郵件設置:如何從Web.config文件
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network defaultCredentials="true" host="localhost" port="587" userName="[email protected]" 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;
但憑據始終爲空。我怎樣才能訪問這些值?
請[向下滾動](http://stackoverflow.com/questions/13452530/reading-system-net-mailsettings-smtp-from-web-config/19960769#19960769)看到我的答案。它似乎對大多數人來說效果最好。 –