I have tryed this solution, but on smtp.LoginOAUTH2(userName, accessToken) i receve this error:
Limilabs.Client.SMTP.SmtpResponseException: 'Authentication unsuccessful [MR1P264CA0044.FRAP264.PROD.OUTLOOK.COM]'
The token used is generated from:
IPublicClientApplication app;
string clientId = "client-id";
string[] msScopes = {
"offline_access",
"email",
"Mail.Send",
"https://graph.microsoft.com/IMAP.AccessAsUser.All",
"https://graph.microsoft.com/SMTP.Send" };
app = PublicClientApplicationBuilder.Create(clientId)
.WithAuthority(
AadAuthorityAudience.AzureAdAndPersonalMicrosoftAccount)
.WithDefaultRedirectUri()
.Build();
var result = await app.AcquireTokenInteractive(msScopes)
.ExecuteAsync();
userName = result.Account.Username;
accessToken = result.AccessToken;