Reputation: 25132
sHi folk,
I've been storing SQL connection strings in web.conf which is fine but now I need to store SMTP credentials somewhere protected. web.conf seems like the likeliest place since its protected but how can they be stored?
I've added the details to my web.conf but amnot sure how to reference them
<system.net>
<mailSettings>
<smtp>
<network
host ="server"
userName ="username"
password ="password"
defaultCredentials =" false"
port =" 25"
/>
</smtp>
</mailSettings>
</system.net>
Sending the mail:
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
Upvotes: 1
Views: 7046
Reputation: 13012
You can take a few approaches. Each has its merits.
In case you were asking specifically how to store SMTP credentials in a web.config file, you could do something like this :
<configuration>
<appSettings>
<add key="SMTP_Server" value="my.smtpserver.com" />
<add key="SMTP_Username" value="myusername" />
<add key="SMTP_Password" value="mypassword" />
</appSettings>
</configuration>
If you need help getting values out of appSettings, check out this article.
Upvotes: 4