title: Send email using smtp and Outlook.Office365.com
body: <p>I am getting hung up on sending emails using outlook.office365.com and ASP.NET.</p>
  
  <p>I am passing in the email address from my contact form as the "FROM" email.  If I change the "FROM" address from the contact form input to just "no-reply@mydomain.com" it works.  Apparently there is a missing step if you are sending emails from a different domain that what the mail server is on.</p>
  
  <p>Here is my error: "System.Net.Mail.SmtpException: Mailbox unavailable. The server response was: 5.7.60 SMTP; Client does not have permissions to send as this sender".   I looked this up and the results were pretty much telling me to set permissions in my Outlook client, which I am not using.</p>
  
  <p>Please let me know where I'm going wrong.  Thanks</p>
  
  <p>I am using the following authentication to send my emails:</p>
  
  <pre><code>//msg.From = new MailAddress("no-reply@plassonusa.com", "What's Up");
  //This is the From I want to use.  The 1st one is the only one that works
  msg.From = new MailAddress(txtEmail.Text, "What's Up");
  msg.To.Add(emailTo);
  msg.Subject = "my subject";
  
  msg.IsBodyHtml = true;
  msg.Body = "foo";
  
  msg.Priority = MailPriority.High;
  
  var smtpClient = new SmtpClient("outlook.office365.com", 587)
  {
      DeliveryMethod = SmtpDeliveryMethod.Network,
      UseDefaultCredentials = false,                              
      Credentials = new NetworkCredential("no-reply@domain.com", "mypassword"),
      EnableSsl = true
  };
  
  if (msg.To.Count &gt; 0)
  {
      try
      {
          smtpClient.Send(msg);
      }
      catch (Exception ex)
      {
          var error = ex.ToString();
      }
  
  }
  </code></pre>