In my MVC4 application, I'm trying to get mail sent using Web.config for configuration settings. I have papercut running as a mock SMTP server. When I try to use smtpClient and set host="localhost" in my code (that is, not through Web.config) everything works just fine.
My Web.config
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network
host="localhost"
userName=""
password=""
defaultCredentials="true" />
</smtp>
</mailSettings>
</system.net>
My code
SmtpClient client = new SmtpClient();
client.Send(myEmailObject);
The error
The SMTP host was not specified
There are multiple web.config's in a ASP.NET MVC application. In order for most of the system related settings to take effect, they have to be placed inside the application's root web.config. That means the one that the server sees as "~/web.config" and that is in the root folder of the Visual Studio solution.
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