This topic is locked

SMTP - Override Settings with Table values

4/9/2019 10:27:06 AM
ASPRunner.NET General questions
D
DennisB author

I am trying to provide a way for replacing the Email Settings after web project is deployed. I have created a table named SMTP in the database and in App Init can display those values. My idea is to provide a table so when deployed an Admin need only edit the table with new values, such as user name, password, host (server) etc. (database connection is in the web.config file and this could be edited after deployment). I have found sample code on the Internet for updating an appsettings.json file or app.config file. However, that does not seem to be what I need to do for an Asprunner.net deployment.
The code below works and shows the values from that table.
{

var rs = GlobalVars.dal.Table("smtp","","").QueryAll();

XVar data;

while (data = CommonFunctions.db_fetch_array(rs))

{

MVCFunctions.Echo(String.Format("{0},{1},{2},{3},{4}
", data["username"],data["smtpfrom"],data["password"],data["host"], data["port"]));

}
What I have not figured out is how to replace the values below with the values from the table. Can anyone give me a hint as to what code would take the values from the database table and replace the settings at run time.
The corresponding items in the appsettings file looks like below.
GlobalVars.globalSettings.InitAndSetArrayItem("user@yourcompany.com", "strSMTPUser");

GlobalVars.globalSettings.InitAndSetArrayItem("your mail server", "strSMTPServer");

GlobalVars.globalSettings.InitAndSetArrayItem("587 - default is 25 but this can be blocked by firewall etc", "strSMTPPort");

GlobalVars.globalSettings.InitAndSetArrayItem("Password for your SMTP Username", "strSMTPPassword");

GlobalVars.globalSettings.InitAndSetArrayItem("noreply@yourcompany.com", "strFromEmail");
How can I replace these values with the ones from my smtp table?
Thanks