The question is too simple, but still appreciate the short answer. I would like to SmtpClientretrieve the username / password from the file App.config. From the MSDN / schema, I realized that the correct file (excerpt) should look like this:
<system.net>
<mailSettings>
<smtp from="foo@bar.com">
<network
host="mail.bar.com"
port="25"
userName="foouser"
password="barpassword"
/>
</smtp>
</mailSettings>
</system.net>
I am trying to find a suitable API to call when initializing the state SmtpClient, so that the mail and password are well extracted from XML:
var client = new SmtpClient( ... );
client.Credentials = new NetworkCredential( ... , ... );
client.Send(message);
Is there a correct / selected method to extract servername, user, passwordor do I just need to call the "usual" the API, for example ConfigurationManager.AppSettings["server"]?
source
share