views:

30

answers:

1

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"]?

+2  A: 

Nothing special is needed, just initialize and send :)

SmtpClient client = new SmtpClient();
client.Send(mymessagehere);

That is all, it will pull from the config.

Mitchel Sellers
thanks a lot! I've suspected it might be simple :) Read the MSDN, looked for something similar, but couldn't find. Better luck next time :)
BreakPhreak
I'll accept the answer in 6 minutes, the system says that waiting is important.
BreakPhreak