title: SmtpClient "Request failed; Mailbox unavailable"
body: <p>Im trying to send and Email with SmtpClient at the yahoo smtp server </p>
  
  <blockquote>
    <p>"smtp.mail.yahoo.com", 587</p>
  </blockquote>
  
  <p>The first time trying, I got an email telling me to change my account settings to allow smtp requests to work, but after doing that, the mailbox is unavailable.</p>
  
  <p>SendMail method:</p>
  
  <pre><code>public void SendMail(string name, string from, string to, string subject, string content)
      {
          try
          {
              using (var mail = new MailMessage())
              {
                  const string email = @"mail@yahoo.com";
                  const string pw = "***";
  
                  var login = new NetworkCredential(email, pw);
  
                  mail.From = new MailAddress(from);
                  mail.To.Add(new MailAddress(to));
                  mail.Subject = subject;
                  mail.Body = content;
                  mail.IsBodyHtml = true;
  
                  try
                  {
                      using (var client = new SmtpClient("smtp.mail.yahoo.com", 587))
                      {
                          client.EnableSsl = true;
                          client.DeliveryMethod = SmtpDeliveryMethod.Network;
                          client.UseDefaultCredentials = false;
                          client.Credentials = login;
                          client.Send(mail);
                      }
                  }
                  finally
                  {
                      mail.Dispose();
                  }
              }
          }
          catch(Exception ex)
          {
  
          }
      }
  </code></pre>
  
  <p>Action:</p>
  
  <pre><code>[HttpPost]
      public ActionResult ContactSend(Mail mail)
      {
          if(ModelState.IsValid)
          {
              var toAdress = @"tomail@yahoo.de";
              var fromAdress = mail.Email;
              var subject = mail.Betreff;
              var name = mail.Name;
              var content = new StringBuilder();
              content.Append("Name: " + name + "\n");
              content.Append("Email: " + fromAdress + "\n\n");
              content.Append(mail.Content);
  
              SendMail(name, fromAdress, toAdress, subject, content.ToString());
  
          }
  
          return RedirectToAction("Kontakt", "Home");
      }
  </code></pre>
  
  <p>Checked all the login information and since i got an email from yahoo the first time i tried it they seem to work.</p>
  
  <p>Exception:</p>
  
  <ul>
  <li>Response    {System.Web.HttpResponseWrapper}    System.Web.HttpResponseBase {System.Web.HttpResponseWrapper}</li>
  <li>ex  {"Postfach nicht verfügbar. Die Serverantwort war: Request failed; Mailbox unavailable"}    System.Exception {System.Net.Mail.SmtpException}</li>
  <li>Data    {System.Collections.ListDictionaryInternal} System.Collections.IDictionary {System.Collections.ListDictionaryInternal}
      HResult -2146233088 int
      HelpLink    null    string</li>
  <li>InnerException  null    System.Exception
      Message "Postfach nicht verfügbar. Die Serverantwort war: Request failed; Mailbox unavailable"  string
      Source  "System"    string
      StackTrace  "   bei System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response)\r\n   bei System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, MailAddress from, Boolean allowUnicode)\r\n   bei System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, Boolean allowUnicode, SmtpFailedRecipientException&amp; exception)\r\n   bei System.Net.Mail.SmtpClient.Send(MailMessage message)\r\n   bei Makler.Controllers.HomeController.SendMail(String name, String from, String to, String subject, String content) in C:\Users\Joshua\source\repos\Makler\Makler\Controllers\HomeController.cs:Zeile 90."  string
      StatusCode  MailboxUnavailable  System.Net.Mail.SmtpStatusCode</li>
  <li>TargetSite  {Void CheckResponse(System.Net.Mail.SmtpStatusCode, System.String)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}</li>
  <li>Static members      </li>
  <li>Non-Public members      </li>
  <li>this    {Makler.Controllers.HomeController} Makler.Controllers.HomeController</li>
  </ul>