title: Can I send SMTP email through Office365 shared mailbox?
body: <p>We are thinking about moving to O365; however, we developed software that uses our current Exchange server to send email both to external users as well as to a support box when errors occur.</p>
  
  <p>I've been testing this to ensure that the code we have in place will continue to work with O365 but so far, I have not been very successful.</p>
  
  <p>I have tried using .Net's SmtpClient as well as MailKit's SmtpClient and neither one seems to work.  I keep getting error (this is the error from MailKit -- the .Net error is similar)</p>
  
  <blockquote>
    <p>"AuthenticationInvalidCredentials: 5.7.3 Authentication unsuccessful [*.prod.exchangelabs.com]"</p>
  </blockquote>
  
  <p>I can use the credentials that I have in my code to log into OWA -- so I know the credentials are valid.  Is it not possible to send email via O356?  Is there any special configuration that has to happen in Exchange to make this possible?</p>
  
  <p>Here is what I've tried so far:</p>
  
  <p><strong>MailKit</strong></p>
  
  <pre class="lang-cs prettyprint-override"><code>var msg = new MimeMessage();
  msg.From.Add(new MailboxAddress("Support","support@mydomain.com"));
  msg.To.Add(new MailboxAddress("Me","me@mydomain.com"));
  msg.To.Add(new MailboxAddress("External User","euser@externaldomain.com"));
  msg.Subject = "Test";
  msg.Body = new TextPart("plain"){
     Text = "Here is a message for you"
  };
  using(var client = new SmtpClient()){
      client.ServerCertificateValidationCallback = (s,c,h,e) =&gt; true;
      client.AuthenticationMechanisms.Remove("XOAUTH2"); //Not sure what this does.  Have tried with and without
      client.Connect("smtp.office365.com", 587, MailKit.Security.SecureSocketOptions.StartTls);
      client.Authenticate(new NetworkCredential("support@mydomain.com", "supportPwd"));
      client.Send(msg);
      client.Disconnect(true);
  }
  </code></pre>
  
  <p>The .Net SmtpClient code looked very similar to the MailKit code.</p>
  
  <ol>
  <li>Is there a way to send through O365 with a licensed user? (code above)</li>
  <li>Are there any special settings required in Exchange or on the licensed user to make this work? (If the answer to 1 is yes)</li>
  <li>Is it possible to send email through a shared mailbox for which the credentialed user has Send As rights?</li>
  </ol>
  
  <p><strong>Update</strong></p>
  
  <p>I'm still getting the same error message.  We do have MFA enabled for our domain users.  However, we have a policy that does not require MFA for users when they are signing in from a trusted location (our org's IP).  I also listed our IP as a Trusted IP.  In my mind, MFA shouldn't be the issue here.</p>
  
  <p>I know the credentials are correct.  I copied them from the code and pasted them in to the login screen when signing into M365 -- and I got in just fine.</p>
  
  <p>What am I doing wrong?</p>