1
我已經存儲web.conf這是很好的SQL連接字符串,但現在我需要存儲的地方保護SMTP憑據。 web.conf似乎是受保護的最可能的地方,但它們如何被存儲?
我已經添加了細節,我web.conf但amnot知道如何引用它們
<system.net>
<mailSettings>
<smtp>
<network
host ="server"
userName ="username"
password ="password"
defaultCredentials =" false"
port =" 25"
/>
</smtp>
</mailSettings>
</system.net>
發送郵件:
Dim mail As New MailMessage()
'set the addresses
mail.From = New MailAddress("[email protected]")
mail.To.Add(ToAddress)
'set the content
mail.Subject = "User Request Submitted via Client Portal"
mail.Body = "text in here"
mail.IsBodyHtml = True
' authenticatin
Dim basicAuthenticationInfo As New System.Net.NetworkCredential("username", "-password-")
'send the message
Dim smtp As New SmtpClient("servername")
smtp.UseDefaultCredentials = False
smtp.Credentials = basicAuthenticationInfo
smtp.Send(mail)
- Jonesy
感謝您的回覆拜倫!我想用你的第二個重點,但不知道如何去做。我找到了一個將詳細信息存儲在web.conf中的示例,但我如何在後面的代碼中引用它們?我用web.conf代碼更新了我的帖子。 – iamjonesy 2010-04-08 15:21:36
Byron的例子給出了答案:將它們存儲在appSettings鍵中是最簡單的。要檢索一個密鑰的值,使用'ConfigurationManager.AppSettings(「[key]」)' – tloflin 2010-04-08 15:28:45
忘記我的最後一條評論,答案是你不需要參考web.conf中的smtp設置,它們是自動使用的。 @tloflin - 我會嘗試appSettings謝謝! – iamjonesy 2010-04-08 15:35:05