sHi folk,
我一直在web.conf中存储SQL连接字符串,这很好,但现在我需要将SMTP凭据存储在受保护的地方。 web.conf似乎是受保护的最有可能的地方,但它们如何存储?
我已将详细信息添加到我的web.conf但不确定如何引用它们
<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("billy.jones@networkroi.co.uk")
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)
- 琼西
答案 0 :(得分:4)
您可以采取一些方法。每个都有其优点。
如果您具体询问如何在web.config文件中存储SMTP凭据,您可以执行以下操作:
<configuration>
<appSettings>
<add key="SMTP_Server" value="my.smtpserver.com" />
<add key="SMTP_Username" value="myusername" />
<add key="SMTP_Password" value="mypassword" />
</appSettings>
</configuration>
如果您需要帮助从appSettings中获取值check out this article。