Reputation: 18993
I have application that fetches email configuration settings such as host (SMTP Server name), username (SMTP Username) and Password from App.Config File as shown below
<system.net>
<mailSettings>
<smtp from="[email protected]"><network host="smtp.gmail.com" userName="[email protected]" port="25" password="PassworD"/>
</smtp>
</mailSettings>
</system.net>
Now i wish to configure the settings that i have set in database and NOT from App.Config File. From database the credentials are not available in SMTPClient's properties .FYI, they are saved in database as well as the values are also correct.
Please Help!
Thanks
Upvotes: 0
Views: 1282
Reputation: 12417
When you instantiate the SMTPClient just set the values specifically there. This overrides the settings from your app.config/web.config file.
var msg = new System.Net.Mail.MailMessage("[email protected]", "[email protected]", "Subject", "Body text...");
var c = new System.Net.Mail.SmtpClient("smtp.gmail.com", 25);
c.Credentials = new System.Net.NetworkCredential("[email protected]", "PassworD");
c.Send(msg);
Upvotes: 1
Reputation: 250
when you were using the web.config version the settings were automatically filled in for you. Now as you have saved it in DB, you need to specify the settings.
Upvotes: 0