c# - Proper way to pass username/password to SmtpClient (.NET) -
The questions are very simple, but still appreciate the short answer. I have to get a username / password from the smtpClient
to the App.config
file with the MSDN / schema I think the proper file should look like:
& lt; System.net & gt; & Lt; MailSettings & gt; & Lt; Smtp from = "foo@bar.com" & gt; & Lt; Network host = "mail.bar.com" port = "25" username = "foosur" password = "barpassword" /> & Lt; / Smtp & gt; & Lt; / MailSettings & gt; & Lt; /system.net> I am trying to find the appropriate API to call when the state is started, so that mail and password are well received from XML. Could: var Client = New SmtpClient (...); // How to get the server name Client.Credentials = New network credentials (..., ...); // How to get a user / pass client Send (message); Is there a reasonable / dedicated way to bring servername
, user
, password
Code> ConfigurationManager.AppSettings ["server"]
?
There is no special need, just start and send :)
SmtpClient Client = new smtpClient (); Client.Send (mymessagehere);
All this, it will pull from config.
Comments
Post a Comment