0

I have to implement message sending via outlook account but every time I authenticate smtp client library throws an exception also I can mention that with imap client everything works fine.

535: 5.7.3 Authentication unsuccessful

My code:

private const string SmtpLink;

await base.SmtpClient.ConnectAsync(SmtpLink, 587, SecureSocketOptions.StartTls);

SaslMechanism oauth2;
const string authMechanism = "OAUTHBEARER";

if (base.SmtpClient.AuthenticationMechanisms.Contains(authMechanism))
    oauth2 = new SaslMechanismOAuthBearer(account.Email, credentials.AccessToken);
else
    oauth2 = new SaslMechanismOAuth2(account.Email, credentials.AccessToken);

await base.SmtpClient.AuthenticateAsync(oauth2);

I am using MailKit library. I have spent a lot of time for searching solution but nothing helped. Hope someone will help

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45

1 Answers1

1

Are you using a personal account? There's currently a problem with XOAUTH for personal accounts (hotmail.com, outlook.com).

Here are some details: https://learn.microsoft.com/en-us/answers/questions/1168272/oauth2-for-smtp-send-granting-accesstoken-but-retu

Nevca
  • 194
  • 1
  • 1
  • 9
  • Hi. Yes I am using personal account. I see. Ok we will wait for actions from microsoft – Valentin Maschenko Feb 07 '23 at 15:26
  • I can also confirm that there is currently ongoing issue with their SMTP OAUTH2. IMAP and POP work fine with OAUTH2. Apparently the basic authentication (username/password) without OAUTH2 works fine (for SMTP) while OAUTH2 does not. – Coder12345 Feb 07 '23 at 22:10