Forums: SMTP Settings - Read from File not hard coded - Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

SMTP Settings - Read from File not hard coded Email SMTP Setting are written appsettings but read from DLL only Rate Topic: -----

#1 User is offline   DennisB 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 09-February 19

Posted 14 March 2019 - 02:50 PM

I recently learned that when you set up email - for registration, forgotten email, after events and so on, the server, username and password are written to a file appsettings - which made sense to me. I would expect, just like changing database connection information - in the web.config file - this app setting file would be where a customer could edit a file to enter their smtp info - their username, their password etc. This is not the case. The Email settings are read from the dll file created when you compile your ASPRunner web application - why bother writing them to a configuration file was my first thought. Is anyone developing web applications for others, customers maybe, to run from their own web servers rather than one you might provide? Have you found a way to allow others to Edit their email settings themselves? Rather than supply you their email credentials and have you compile and redeploy your application.

So my concern is I want to supply a web application with generic or sample credentials (like "your username" and "Your Password" and "Your Server Name" and "Your port" that could be edited by the customer, and I don't want to have to recompile with their information embedded in a .dll and say here, replace the dll of the same name.

Does anyone else find this a problem or concern? Have a suggestion?

Thanks
0

#2 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16278
  • Joined: 03-February 03
  • Gender:Male

Posted 14 March 2019 - 05:28 PM

There are many ways to make it work. Nobody ever asked it, I guess this is not a common setup setup.

SMTP settings are being set in include/appsettings.cs file

			GlobalVars.globalSettings.InitAndSetArrayItem(false, "useCustomSMTPSettings");
			GlobalVars.globalSettings.InitAndSetArrayItem("", "strSMTPUser");
			GlobalVars.globalSettings.InitAndSetArrayItem("localhost", "strSMTPServer");
			GlobalVars.globalSettings.InitAndSetArrayItem("25", "strSMTPPort");
			GlobalVars.globalSettings.InitAndSetArrayItem("", "strSMTPPassword");
			GlobalVars.globalSettings.InitAndSetArrayItem("", "strFromEmail");


You can add your code to AfterAppInit event that will override hard coded settings with your own ones. You can store SMTP settings either in web.config or in the database. Considering the nature of your application web.config is probably a better option.

Here is the article that explains how you can read settings from web.config:
https://asprunner.co...nection-string/
Best regards,
Sergey Kornilov
0

#3 User is offline   DennisB 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 09-February 19

Posted 14 March 2019 - 05:44 PM

View Postadmin, on 14 March 2019 - 12:28 PM, said:

There are many ways to make it work. Nobody ever asked it, I guess this is not a common setup setup.

SMTP settings are being set in include/appsettings.cs file

			GlobalVars.globalSettings.InitAndSetArrayItem(false, "useCustomSMTPSettings");
			GlobalVars.globalSettings.InitAndSetArrayItem("", "strSMTPUser");
			GlobalVars.globalSettings.InitAndSetArrayItem("localhost", "strSMTPServer");
			GlobalVars.globalSettings.InitAndSetArrayItem("25", "strSMTPPort");
			GlobalVars.globalSettings.InitAndSetArrayItem("", "strSMTPPassword");
			GlobalVars.globalSettings.InitAndSetArrayItem("", "strFromEmail");


You can add your code to AfterAppInit event that will override hard coded settings with your own ones. You can store SMTP settings either in web.config or in the database. Considering the nature of your application web.config is probably a better option.

Here is the article that explains how you can read settings from web.config:
https://asprunner.co...nection-string/


Thank you this may be what I needed. I wonder why these settings are written to the appsettings.cs file but then not used? But I think this may allow me to remove my own mail settings and use the settings from the appsettings files as I had expected.

I appreciate today's response.
0

#4 User is offline   admin 

  • Administrator
  • PipPipPip
  • Group: Admin
  • Posts: 16278
  • Joined: 03-February 03
  • Gender:Male

Posted 15 March 2019 - 04:23 PM

Settings written to appsettings.cs are being used. You need to understand that ASP.NET compiles sources .cs files to DLLs and this is where your code resides. .cs files are not required for deployment but come handy when you need to open project in Visual Studio and do some troubleshooting.
Best regards,
Sergey Kornilov
0

#5 User is offline   DennisB 

  • Member
  • PipPip
  • Group: Members
  • Posts: 15
  • Joined: 09-February 19

Posted 15 March 2019 - 04:43 PM

View Postadmin, on 15 March 2019 - 11:23 AM, said:

Settings written to appsettings.cs are being used. You need to understand that ASP.NET compiles sources .cs files to DLLs and this is where your code resides. .cs files are not required for deployment but come handy when you need to open project in Visual Studio and do some troubleshooting.


I understand and agree. I also agree with a private email you wrote suggesting that I should put smtp settings in the web.config file, as the database connection info is read from the web.config - so if after deployment, there is a need to change the database settings this could be done in the web.config file. Similarly, this would seem to be a good place for ASPRunner.net to store the smtp settings rather than stored in the compiled .dll file. This means that by your suggestion I have to add event code before app init to read the web.config (which would have been a good place in the first place for ASPRunner to write the smtp info) file to get the smtp settings and use those settings instead of the hard coded smtp values.

Also after some trial and error I had to find out after making the changes you suggested - by way of a link to a website - that I needed to put the web.config file in the source folder so it would not be overwritten on every output.

Thanks for the reply.
0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users