SmtpClient does not read Web.config

In my MVC4 application, I am trying to get mail sent using Web.config for configuration settings. My papercut works as an SMTP mock server. When I try to use smtpClient and set host = "localhost" in my code (that is, not through Web.config), everything works fine.

My web.config

<system.net> <mailSettings> <smtp deliveryMethod="Network" from=" someone@somewhere.net "> <network host="localhost" userName="" password="" defaultCredentials="true" /> </smtp> </mailSettings> </system.net> 

My code

 SmtpClient client = new SmtpClient(); client.Send(myEmailObject); 

Error

SMTP host not specified

+4
source share
1 answer

An ASP.NET MVC application has several web.config. For most of the system-related parameters to take effect, they must be placed inside the web.config root application. This means that the server sees "~ / web.config" and is located in the root folder of the Visual Studio solution.

+12
source

Source: https://habr.com/ru/post/1469079/


All Articles