4
votes

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

1
There are multiple web.config's in a WPF application. Did you try putting it into the one in the app's root directory?Roman Gruber
That's soooo true, I'm an a$%^#s editing the Web.config in the Views folder all night, banging my head on the keyboard. Thx! Can you post that as an actual answer so I can give you the kudos and close my question. (I'm a bit embarrassed you know :)GerardV
Added the answer... don't worry, I have seen several people make the same mistake. You are not alone :)Roman Gruber

1 Answers

13
votes

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.