title: Sending mail with Postal library in MVC 5
body: <p>I'm using the Postal library to send emails from the contact page. I have the following code:</p>
  
  <p><strong>ContactEmail</strong></p>
  
  <pre><code>using AccessorizeForLess.ViewModels;
  using Postal;
  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.ComponentModel.DataAnnotations;
  using System.Linq;
  using System.Web;
  using System.Web.Mvc;
  
  namespace AccessorizeForLess.Models
  {
      public class ContactEmail : Email
      {
          public string To { get; set; }
  
          [DataType(DataType.EmailAddress)]
          [DisplayName("Email Address")]
          [RegularExpression(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$", ErrorMessage = "The Email field is not valid, Please enter a valid email address!")]
          [Required(ErrorMessage="Email address is required.")]
          public string From { get; set; }
  
          [DisplayName("First Name")]
          [Required(ErrorMessage="Please provide your first name")]
          public string FirstName { get; set; }
  
          [DisplayName("Last Name")]
          [Required(ErrorMessage="Please provide your last name")]
          public string LastName { get; set; }
  
          [DisplayName("Subject")]
          [Required(ErrorMessage="Please select a topic")]
          public SelectList Subject { get; set; }
          public string SelectedSubject { get; set; }
  
          [DisplayName("Message")]
          [DataType(DataType.MultilineText)]
          [Required(ErrorMessage="PLease provide a message for the email")]
          public string Message { get; set; }
  
          public List&lt;EmailSubjectViewModel&gt; Subjects { get; set; }
      }
  }
  </code></pre>
  
  <p><strong>EmailSubjectViewModel</strong></p>
  
  <pre><code>namespace AccessorizeForLess.ViewModels
  {
      public class EmailSubjectViewModel
      {
          public int Id { get; set; }
          public string Subject { get; set; }
      }
  }
  </code></pre>
  
  <p><strong>ContactController</strong></p>
  
  <pre><code>public ActionResult Index()
          {
              List&lt;EmailSubjectViewModel&gt; Subjects = new List&lt;EmailSubjectViewModel&gt;()
              {
                  new EmailSubjectViewModel(){Id=1, Subject="Website Issues"},
                  new EmailSubjectViewModel(){Id=2, Subject="Order Issue"},
                  new EmailSubjectViewModel(){Id=3, Subject="Product Question"},
                  new EmailSubjectViewModel(){Id=4, Subject="Returns Questions"},
                  new EmailSubjectViewModel(){Id=5, Subject="Other"}
              };
  
              ContactEmail email = new ContactEmail()
              {
                  Subjects = Subjects
              };
              return View(email);
          }
  
  
          public ActionResult Send(ContactEmail email)
          {
              ContactEmail e = new ContactEmail();
              e.From = email.From;
              e.FirstName = email.FirstName;
              e.LastName = email.LastName;
              e.SelectedSubject = email.SelectedSubject;
              e.Message = email.Message;
  
              e.Send();
              return View();
          }
  </code></pre>
  
  <p>And last but not least my view:</p>
  
  <pre><code>@model AccessorizeForLess.Models.ContactEmail
  @{
      ViewBag.Title = "Contact";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;h2&gt;Contact&lt;/h2&gt;
  
  @using (Html.BeginForm("Send", "Contact", FormMethod.Post))
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;AccessorizeForLess.net&amp;nbsp;&amp;nbsp;&amp;nbsp;
              &lt;a href="https://www.facebook.com/accessorize5orless" target="_blank" title="Accessorize For Less On Facebook"&gt;&lt;img src="~/Content/icon-facebook.png" /&gt;&lt;/a&gt;&lt;/h4&gt;
          &lt;div style="color:red;font-weight:bold;"&gt;@ViewBag.Message&lt;/div&gt;
  
          &lt;hr /&gt;
          @Html.ValidationSummary(true)
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.FirstName, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.FirstName)
                  @Html.ValidationMessageFor(model =&gt; model.FirstName)
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.LastName, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.LastName)
                  @Html.ValidationMessageFor(model =&gt; model.LastName)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.From, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.From)
                  @Html.ValidationMessageFor(model =&gt; model.From)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.SelectedSubject, "Category", new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.DropDownListFor(model =&gt; model.SelectedSubject, new SelectList(Model.Subjects, "Id", "Subject"), "- Please Select -")
                  @Html.ValidationMessageFor(model =&gt; model.SelectedSubject)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.Message, new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.EditorFor(model =&gt; model.Message, new { @cols = "25", @rows = "55" })
                  @Html.ValidationMessageFor(model =&gt; model.Message)
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10"&gt;
                  &lt;input type="submit" value="Send" class="btn btn-default" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
    &lt;/div&gt;
  
  
  }
  </code></pre>
  
  <p>Oops almost forgot the section in my web.config</p>
  
  <pre><code>&lt;system.net&gt;
      &lt;mailSettings&gt;
        &lt;smtp deliveryMethod="Network" from="admin@accessorizeforless.net"&gt;
          &lt;network host="smtp.gmail.com" port="587" enableSsl="true" defaultCredentials="true" userName="***********@gmail.com" password="**********" /&gt;
        &lt;/smtp&gt;
      &lt;/mailSettings&gt;
    &lt;/system.net&gt;
  </code></pre>
  
  <p>Now when I fill out the form and click send I get the following error:</p>
  
  <blockquote>
    <p>System.Net.Mail.SmtpException: The SMTP server requires a secure
    connection or the client was not authenticated. The server response
    was: 5.5.1 Authentication Required.</p>
  </blockquote>
  
  <p>I thought I was setting the authenticatioon credentials in the web.config?</p>