title: GoDaddy Office 365 OAuth2 for SMTP fails with Authentication unsuccessful
body: <p>Following <a href="https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth" rel="nofollow noreferrer">this guide</a> on OAuth2 support for IMAP/SMTP, I was able to retrieve the access token and authenticate IMAP and SMTP fine, but for some Office 365 accounts like the ones that were bought from GoDaddy, AUTH XOAUTH2 command returns Authentication unsuccessful as shown in logs below.</p>
  <pre><code>Connecting to 'smtp.office365.com:587', SSL/TLS: False.
  S: 220 AM7PR02CA0017.outlook.office365.com Microsoft ESMTP MAIL Service ready at Fri, 14 Aug 2020 12:24:06 +0000
  C: EHLO [127.0.0.1]
  S: 250-AM7PR02CA0017.outlook.office365.com Hello [79.185.54.24]
  S: 250-SIZE 157286400
  S: 250-PIPELINING
  S: 250-DSN
  S: 250-ENHANCEDSTATUSCODES
  S: 250-STARTTLS
  S: 250-8BITMIME
  S: 250 SMTPUTF8
  C: STARTTLS
  S: 220 2.0.0 SMTP server ready
  C: EHLO [127.0.0.1]
  S: 250-AM7PR02CA0017.outlook.office365.com Hello [79.185.54.24]
  S: 250-SIZE 157286400
  S: 250-PIPELINING
  S: 250-DSN
  S: 250-ENHANCEDSTATUSCODES
  S: 250-AUTH LOGIN XOAUTH2
  S: 250-8BITMIME
  S: 250 SMTPUTF8
  C: AUTH XOAUTH2 *PASSWORD*
  S: 535 5.7.3 Authentication unsuccessful [AM7PR02CA0017.eurprd02.prod.outlook.com]
  </code></pre>
  <p>URLs below are used for authorization:</p>
  <ul>
  <li><a href="https://login.microsoftonline.com/common/oauth2/v2.0/authorize" rel="nofollow noreferrer">https://login.microsoftonline.com/common/oauth2/v2.0/authorize</a></li>
  <li><a href="https://login.microsoftonline.com/common/oauth2/v2.0/token" rel="nofollow noreferrer">https://login.microsoftonline.com/common/oauth2/v2.0/token</a></li>
  </ul>
  <p>Scope for SMTP used: <a href="https://outlook.office.com/SMTP.Send" rel="nofollow noreferrer">https://outlook.office.com/SMTP.Send</a> (as documented in the guide from Microsoft). In the Azure portal, it is added in Permissions API under Graph API (since it is not available under Exchange anymore).</p>
  <p>The app is registered for both personal Outlook.com users and Office 365 organizations in Azure (that is why common is used as a tenant in auth URLs).</p>
  <p>It works for our developer license Office 365 organization but for the one that is bought through GoDaddy (on <a href="https://www.godaddy.com/email/professional-business-email" rel="nofollow noreferrer">https://www.godaddy.com/email/professional-business-email</a>) it fails to authenticate SMTP (IMAP works fine).</p>
  <p>Things already tried:</p>
  <ul>
  <li>Limiting scopes to the ones related to Exchange resource (as suggested in <a href="https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/exchange/client-developer/legacy-protocols/how-to-authenticate-an-imap-pop-smtp-application-by-using-oauth</a>)</li>
  <li>Changing tenant to organizations in auth URLs (instead of common)</li>
  <li>Using <a href="https://outlook.office365.com/SMTP.Send" rel="nofollow noreferrer">https://outlook.office365.com/SMTP.Send</a> as scope for SMTP</li>
  </ul>
  <p>Any suggestions?</p>