I would like to send email differently on production then the development environment, such as sending emails only to me while testing. I know that I can set an application value in the webconfig file or check the url before sending the emails. I would like to know what is the best practice for doing this or if there is some other option that I don't know about that might be better? Any information on this topic would be greatly appreciated.
I use what's called Preprocessor Directives (in C#). In VB it's called Directives only.
I have a helper method like this:
public static bool IsDebug()
{
#if DEBUG
return true;
#else
return false;
#endif
}
Then anywhere in the code one can call this method and during runtime and it'll tell if the code is being run in Debug
( development ) or if it's the Release
version ( production ).
Here's the equivalent #If...Then...#Else Directives in (VB).
If you want to only send the email to yourself if it's not Production then do it by changing the email address on the "To" field.
So either change it in the database or config file, wherever you put that value.
The way the application determines if you are in the development server is with the "ASPNETCORE_ENVIRONMENT".
You can check this link, Use multiple environments in ASP.NET Core
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With