EDN Admin
Well-known member
Im trying to add a section to my code where I store SmtpMail values in a config file. Only problem is its not reading the values.
Here is where I call the configuraitonManager:
<pre class="prettyprint private int mailReport()
{
// Emailer is my custom class
Emailer myEmailer = new Emailer();
ConfigurationManager.GetSection("appSettings"); // doesnt do anything
myEmailer.SmtpServerAddress = ConfigurationManager.AppSettings["smtpServerAddress"]; //returns blank
myEmailer.AddressesTo = ConfigurationManager.AppSettings["AddressesTo"] //returns blank;
myEmailer.AddressFrom = "testemail@myport.com";
myEmailer.DisplayName = " Report Generator";
myEmailer.Subject = " Test Report";
myEmailer.Attachment = new Attachment(GlobalVar.ReportFileName);
int success = myEmailer.SendMail();
return success;
}[/code]
And thats the only time its ever used. Ive added the System.Configuration reference and dll to my project. The App.Config file I created literally by adding a xml text file to the project and renaming it App.config (is that correct)?
Im not sure if I should "connect" the App.config file to the configuration manager or what! I could sure use some input. Here is the config file btw:
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="SmtpServerAddress" value="smtp.iLa.com" />
<add key="AddressFrom" value="tester@ymail.com" />
<add key="AddressesTo" value="tester@gmail.com" />
<add key="DisplayName" value="Report Generator" />
<add key="Subject" value="Test Report" />
<add key="Body" value="Your copy of the Test Report is attached to this email." />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
</configuration>[/code]
<br/>
View the full article
Here is where I call the configuraitonManager:
<pre class="prettyprint private int mailReport()
{
// Emailer is my custom class
Emailer myEmailer = new Emailer();
ConfigurationManager.GetSection("appSettings"); // doesnt do anything
myEmailer.SmtpServerAddress = ConfigurationManager.AppSettings["smtpServerAddress"]; //returns blank
myEmailer.AddressesTo = ConfigurationManager.AppSettings["AddressesTo"] //returns blank;
myEmailer.AddressFrom = "testemail@myport.com";
myEmailer.DisplayName = " Report Generator";
myEmailer.Subject = " Test Report";
myEmailer.Attachment = new Attachment(GlobalVar.ReportFileName);
int success = myEmailer.SendMail();
return success;
}[/code]
And thats the only time its ever used. Ive added the System.Configuration reference and dll to my project. The App.Config file I created literally by adding a xml text file to the project and renaming it App.config (is that correct)?
Im not sure if I should "connect" the App.config file to the configuration manager or what! I could sure use some input. Here is the config file btw:
<pre class="prettyprint <?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="SmtpServerAddress" value="smtp.iLa.com" />
<add key="AddressFrom" value="tester@ymail.com" />
<add key="AddressesTo" value="tester@gmail.com" />
<add key="DisplayName" value="Report Generator" />
<add key="Subject" value="Test Report" />
<add key="Body" value="Your copy of the Test Report is attached to this email." />
<add key="ClientSettingsProvider.ServiceUri" value="" />
</appSettings>
</configuration>[/code]
<br/>
View the full article