How do you set a global SmtpDeliveryMethod DeliveryMethod in a Blazor application

Viewed 41

In a .Net 4.6 web application, I had a setting in web.config that let me globally set the DeliveryMethod and SpecificPickupLocation for all smtp emails I sent from my application.

web.config section:

<system.net>
  <mailSettings>
    <smtp deliveryMethod="SpecifiedPickupDirectory">
      <specifiedPickupDirectory pickupDirectoryLocation="c:\Temp\" />
    </smtp>
  </mailSettings>
</system.net>

My question is, in a Blazor application where you don't have a web.config, how do you set a similar global setting for smtp

1 Answers

The specifics would be depenent upon your implementation of SMTP, but you could define similar configuration in your appsettings.json file.

https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/configuration?view=aspnetcore-6.0

You could then inject this configuration into your SMTP implementation, similar to this question: How to read appsetting.json from any class blazor serverside

Note that you can have an appsettings.Production.json, and an appsettings.Development.json to easily control configuration based on deployment configuration.

Related