The question is too simple, but still appreciate the short answer. I would like the SmtpClient
to fetch username/password from the App.config
file. From the MSDN/schema I've figured out that the proper file (excerpt) should look like:
<system.net>
<mailSettings>
<smtp from="[email protected]">
<network
host="mail.bar.com"
port="25"
userName="foouser"
password="barpassword"
/>
</smtp>
</mailSettings>
</system.net>
I am trying to find the proper API to call, when initializing SmtpClient
state, so that mail and password will be nicely fetched from the XML:
var client = new SmtpClient( ... ); // how to fetch the servername?
client.Credentials = new NetworkCredential( ... , ... ); // how to fetch user/pass
client.Send(message);
Is there a proper/dedicated way to fetch servername
, user
, password
or should I just call the "regular" API like ConfigurationManager.AppSettings["server"]
?