1
votes

I'm trying to send an email via smtp.live.com using an OAuth token generated via https://login.microsoftonline.com/common/oauth2/v2.0/… but I'm receiving the following error:

535 5.7.3 Authentication unsuccessful

I can make it work by obtaining an auth token via https://login.live.com/oauth20_authorize.srf (a legacy API) but that only works for free Microsoft accounts (I need to support business/Outlook365 accounts too).

The fact I can make it work using that legacy endpoint seems to validate that:

  • The server supports XOAUTH2 (which I also validated via Telnet EHLO)
  • That the encoding is correct (I'm using this process)
  • That I'm meant to pass the full access token via XOAUTH2 and not something odd like pass it in via LOGIN, or decode the JWT and pass in some component etc.

The access token seems valid (it works for other calls, including sending an email via the Graph API).

I've requested the following scopes:

[
  'offline_access', 'User.Read', 'MailboxSettings.ReadWrite',
  'Mail.Send', 'Mail.ReadWrite', 'Mail.Read', 'Mail.ReadBasic', 'Contacts.ReadWrite',
  'Mail.Read.Shared', 'Mail.ReadWrite.Shared', 'Mail.Send.Shared', 'MailboxSettings.Read',
  'profile', 'openid', 'email', 'Calendars.ReadWrite',
  'EAS.AccessAsUser.All', 'EWS.AccessAsUser.All',
];

For the legacy token (the one which works), the scopes are different:

[
  'wl.emails', 'wl.offline_access', 'wl.imap'
];

(I've tried including these scopes when requesting the v2 token too, but it's invalid).

Other things I've tried:

  • Using smtp.office365.com instead of smtp.live.com
  • Obtaining fresh access tokens
  • Ensuring app settings/permissions are configured correctly, as per this article
  • Enable Exchange SMTP Auth
1
First always make 100% sure your credentials are correct. Had this issue today, searched for many solutions, but it was a typo.Dirk Jan

1 Answers

2
votes

Office 365 SMTP servers do not support OAuth authentication as of this time.