如何处理系统。
首先,是C#&的新手VB.NET开发。
在尝试连接到Exchange Server时,会收到以下错误。
System.PlatformNotSupportedException
HResult=0x80131539
Message=Confidential Client flows are not available on mobile platforms or on Mac.See https://aka.ms/msal-net-confidential-availability for details.
Source=Microsoft.Identity.Client
StackTrace:
at Microsoft.Identity.Client.ConfidentialClientApplicationBuilder.Create(String clientId)
at DataLoadLibrary.Email.OAuthTokenProviders.<connect_to_exchange>d__1.MoveNext() in C:\Users\path\to\file\OAuthTokenProviders.cs:line 20
using System;
using Microsoft.Exchange.WebServices.Data;
using Microsoft.Identity.Client;
namespace DataLoadLibrary.Email
{
public class OAuthTokenProviders
{
public OAuthTokenProviders()
{
Console.WriteLine("TESTING INSIDE CONSTRUCT");
connect_to_exchange();
}
static async void connect_to_exchange()
{
// Using Microsoft.Identity.Client
var cca = ConfidentialClientApplicationBuilder
.Create("") //client Id
.WithClientSecret("")
.WithTenantId("")
.Build();
var ewsScopes = new string[] { "https://outlook.office365.com/.default" };
try
{
// Get token
var authResult = await cca.AcquireTokenForClient(ewsScopes)
.ExecuteAsync();
// Configure the ExchangeService with the access token
var ewsClient = new ExchangeService(ExchangeVersion.Exchange2013_SP1);
ewsClient.Url = new Uri("https://outlook.office365.com/EWS/Exchange.asmx");
ewsClient.Credentials = new OAuthCredentials(authResult.AccessToken);
ewsClient.ImpersonatedUserId =
new ImpersonatedUserId(ConnectingIdType.SmtpAddress, "[email protected]");
//Include x-anchormailbox header
ewsClient.HttpHeaders.Add("X-AnchorMailbox", "[email protected]");
// Make an EWS call to list folders on exhange online
var folders = ewsClient.FindFolders(WellKnownFolderName.MsgFolderRoot, new FolderView(10));
foreach (var folder in folders)
{
Console.WriteLine($"Folder: {folder.DisplayName}");
}
// Make an EWS call to read 50 emails (last 5 days) from Inbox folder
TimeSpan ts = new TimeSpan(-5, 0, 0, 0);
DateTime date = DateTime.Now.Add(ts);
SearchFilter.IsGreaterThanOrEqualTo filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, date);
var findResults = ewsClient.FindItems(WellKnownFolderName.Inbox, filter, new ItemView(50));
foreach (var mailItem in findResults)
{
Console.WriteLine($"Subject: {mailItem.Subject}");
}
EmailMessage email = new EmailMessage(ewsClient);
email.ToRecipients.Add("[email protected]");
email.Subject = "HelloWorld";
email.Body = new MessageBody("This is a test email using MS Exchg we services");
email.Send();
}
catch (MsalException ex)
{
Console.WriteLine($"Error acquiring access token: {ex}");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex}");
}
if (System.Diagnostics.Debugger.IsAttached)
{
Console.WriteLine("Hit any key to exit...");
Console.ReadKey();
}
}
}
}
当我在vs Studio中执行上述代码时,要 开发相同的信息移动平台或Mac上的流量不可用。参见 https://aka.ms/msal-net-net-net-net-net-confidential-avialdial-availability 有关详细信息 。请证明一些暗示为什么它会显示出这种例外以及我们如何处理它。提前致谢。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论