Page 1 of 1

Email setting to database

Posted: Thu Jun 16, 2016 2:15 pm
by Danny

Hi,

We work with several Email setting and several customers.

Now we have to rebuild the complete file for every customer because we have to change the email settings.

Is it possible to puth this setting to the database, just like example Dynamic User Levels (migrate to database).

Regards,


Re: Email setting to database

Posted: Fri Jun 17, 2016 1:39 pm
by Webmaster

Just add a table in your database to store them. Problem is: How and when do you want to use the email settings in the database? What are those "email settings"? Different SMTP servers? Senders? Same SMTP server but different usernames and passwords? Explain in detail.


Re: Email setting to database

Posted: Tue Mar 19, 2019 7:35 am
by newbie

I have the same question. In classic asp, Aspmaker - not Aspmaker.net - it seems the ew.cfg file can be edited and this would be where to edit SMTP server info, but with ASPMaker.net you seem to have to read settings from a file then write them. I thought appsetttings.json would be a good place to save/read from but apparently not.


Re: Email setting to database

Posted: Tue Mar 19, 2019 9:42 am
by MichaelG

To access the settings in appsettings.json, just use: Configuration["Section:Key"]

assuming you have the following settings in appsettings.json:

{
"Databases": ...,
"Section": {
"Key": "...",
...
},
"Jwt": {
...
},


Re: Email setting to database

Posted: Wed Sep 04, 2019 9:42 am
by right4

I'm successfully store smtp parameter to appsettings.json but the problems is when deploy to IIS i need to put <environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" /> in web.config,
ewcfg.cs
public static string SmtpServer = Configuration["SMTPConfig:SmtpServer"];

appsettings.json

"SMTPConfig": {
"SmtpServer": "smtp.gmail.com",

error
Application startup exception: System.TypeInitializationException: The type initializer for 'Config'
threw an exception. ---> System.NullReferenceException: Object reference not set to an instance of
an object.


Re: Email setting to database

Posted: Thu Sep 05, 2019 8:22 am
by MichaelG

Check Tools -> Advanced Settings -> Set environment to 'Development' in web.config


Re: Email setting to database

Posted: Thu Sep 05, 2019 9:24 am
by Webmaster

You'd better use Class_Init server event (see Server Events and Client Scripts in the help file) to set SMTP settings, e.g. (v2019)

Config.SmtpServer = "xxx.yyy.zzz"; // SMTP server
Config.SmtpServerPort = 1234; // SMTP server port
Config.SmtpSecureOption = "SSL";
Config.SmtpServerUsername = "user"; // SMTP server user name
Config.SmtpServerPassword = "password"; // SMTP server password


Re: Email setting to database

Posted: Thu Jun 04, 2020 2:54 pm
by Markom
I'm using an smtp server with a self signed certificate. Obviously Mailkit cannot handle that with the settings in Aspnetmaker2020. I followed your suggestion to adapt the class_init server event, leaving the SSL line out, but that made the application unable to start. Any suggestion how and where I can follow op in the Mailkit suggestion on Github to adapt / add MyServerCertificateValidationCallback (see below) ?

bool MyServerCertificateValidationCallback (object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
if (sslPolicyErrors == SslPolicyErrors.None)
return true;

// Note: The following code casts to an X509Certificate2 because it's easier to get the
// values for comparison, but it's possible to get them from an X509Certificate as well.
if (certificate is X509Certificate2 certificate2) {
var cn = certificate2.GetNameInfo (X509NameType.SimpleName, false);
var fingerprint = certificate2.Thumbprint;
var serial = certificate2.SerialNumber;
var issuer = certificate2.Issuer;

return cn == "imap.gmail.com" && issuer == "CN=GTS CA 1O1, O=Google Trust Services, C=US" &&
serial == "0096768414983DDE9C0800000000320A68" &&
fingerprint == "A53BA86C137D828618540738014F7C3D52F699C7";
}

return false;
}

Re: Email setting to database

Posted: Fri Jun 05, 2020 8:10 am
by MichaelG
Try in Email_Sending, create the Mailer first so that you can add customization your needed:

email.Mailer = new SmtpClient();
//... Customize