Trying to access App.config file for mail settings but fails to work.

Posted by mw on Stack Overflow See other posts from Stack Overflow or by mw
Published on 2010-04-13T10:23:17Z Indexed on 2010/04/13 10:33 UTC
Read the original article Hit count: 444

Filed under:
|
|

Hello we have a Business Logic Layer which has an Email Services Class. In this class we have a method which will create an email(This part works and compiles fine). However when we try to access the app config file in order to test the method we get an error saying - Can't retrieve the app config mail settings and says all values are null when they are not. Here is the app config section for our code:


<mailSettings>
  <smtp deliveryMethod="Network" from="[email protected]">
    <network host="localhost" port="25" defaultCredentials="true"/>
  </smtp>
</mailSettings>

Here is there code we use to connect to the app.config:


private System.Net.Configuration.MailSettingsSectionGroup mailSettings;

SmtpClient client = new SmtpClient(mailSettings.Smtp.Network.Host, mailSettings.Smtp.Network.Port);


What are we doing wrong here?

© Stack Overflow or respective owner

Related posts about mailsettings

Related posts about c#