Aşağıdaki şekilde mailbox okumaya çalıştığımda kullanıcıyı login edip token alabiliyorum ancak mailbox a ulaşmaya çalıştığımda “Uzak sunucu hata döndürdü: (401) Onaylanmadı.” hatasını alıyorum

Cem YENİCİ 1 Reputation point
2022-12-06T11:39:29.197+00:00

Aşağıdaki kod ile ofis365 kullanıcı mailbox'a erişmek istediğimizde Uzak sunucu hata döndürdü: (401) Onaylanmadı.” hatasını alıyoruz

var username = "EMAIL";
var password = new NetworkCredential("", "PASSWORD").SecurePassword;
var client = PublicClientApplicationBuilder
.Create("ClientID")
.WithTenantId("TenantId”)
.Build();
var scopes = new string[] { "user.read", "mail.read" };
var result = await client.AcquireTokenByUsernamePassword(scopes, username, password).ExecuteAsync();

            var ewsClient = new ExchangeService();  
            ewsClient.Url = new Uri(https://outlook.office365.com/EWS/Exchange.asmx);  
            ewsClient.Credentials = new OAuthCredentials(result.AccessToken);  
            ewsClient.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, username);  

            ewsClient.HttpHeaders.Add("X-AnchorMailbox", username);  

            Mailbox mb = new Mailbox(username);  

            FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);                  

            Folder inbox = Folder.Bind(ewsClient, fid);  
Community Center | Not monitored
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Anonymous
    2022-12-06T13:42:07.657+00:00

    Q&A forums are currently English only. I'd try asking for help over here in dedicated forums.
    https://social.msdn.microsoft.com/Forums/tr-tr/home
    https://social.technet.microsoft.com/Forums/tr-tr/home
    https://answers.microsoft.com/tr-tr

    --please don't forget to upvote and Accept as answer if the reply is helpful--

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.