title: ASP.NET MVC 3 SMTP MAIL ERROR
body: <p>Here is my web.config</p>
  
  <pre><code>&lt;system.net&gt;
   &lt;mailSettings&gt;
     &lt;smtp from="myemail"&gt;
      &lt;network host="ispsmtpaddress" port="25" userName="user" password="pass"    defaultCredentials="true" /&gt;
      &lt;/smtp&gt;
    &lt;/mailSettings&gt;
  &lt;/system.net&gt;
  </code></pre>
  
  <p>this is below the system.web closing tag</p>
  
  <p>Here is my controller;</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Get)]
        public ViewResult ContactUs()
         {
            return View();
          }
  
        [AcceptVerbs(HttpVerbs.Post)]
         public ViewResult ContactUs(ContactMessage message)
          {
             string successMessage = "Your message was sent successfully.";
  
          try
          {
              MailMessage email = new MailMessage()
              {
                  Subject = "Email from EmailForm",
                  Body = message.MessageBody,
                  IsBodyHtml = false,
                  From = new MailAddress(message.Email, message.Name)
  
  
              };
  
              email.To.Add(new MailAddress("daniel@mailtosendto.com", "Name Of My Project"));
  
              SmtpClient server = new SmtpClient();
  
              server.Send(email);
          }
          catch (Exception ex)
          {
              successMessage = ex.Message;
          }
  
          ViewData["SuccessMessage"] = successMessage;
          return View();
      }
  </code></pre>
  
  <p>here is my model;</p>
  
  <pre><code>  namespace NewAtAClick.Models
  {
      public class ContactMessage
     {
      public string Name { get; set; }
      public string Email { get; set; }
      public string MessageBody { get; set; }
  }
  </code></pre>
  
  <p>}</p>
  
  <p>And my view</p>
  
  <pre><code>  @using (Html.BeginForm())
     {
      &lt;div&gt;
        &lt;p&gt;@ViewData["SuccessMessage"]&lt;/p&gt;
      Name
      &lt;div&gt;
           @Html.TextBox("Name", String.Empty, new { @class = "cls-text-input" })
      &lt;/div&gt;
      Email
      &lt;div&gt;
          @Html.TextBox("Email", String.Empty, new { @class = "cls-text-input" })
      &lt;/div&gt;
      Message
      &lt;div&gt;
           @Html.TextArea("MessageBody")
      &lt;/div&gt;
      &lt;div&gt;
          &lt;input type="submit" value="Submit Message" /&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>This is the error I'm getting on screen</p>
  
  <p>'The smtp host is not specified". I have included my ISP's smtp address in the web.config. I have tried a few different configurations but it won't work. I'm developing on my local machine so I've alse tried locaLhost with no user and pass but nothing. Any help would be greatly appreciated. Thanks!</p>