如何在MSGRAPH .NET SDK中设置用户代理字符串
我正在使用C#中的MSGraph SDK v4.27.0读取客户电子邮件帐户。它运行良好,但一位客户坚持使用允许清单来访问电子邮件。授予对提供用户代理字符串的应用程序的访问,但是如何使用SDK调用将其包含在MSGraph标题中?
代码取自MS示例
var scopes = new[] { "User.Read","Mail.ReadWrite","Mail.ReadWrite.Shared" };
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var userName = strAccount;
var password = strPWD ;
var userNamePasswordCredential = new UsernamePasswordCredential(
userName, password, tenantId, theClientId, options);
var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);
try
{
rootFolder = await graphClient.Me.MailFolders["msgfolderroot"]
.Request()
.GetAsync();
}..
I'm reading customer email accounts using the MSGraph SDK v4.27.0 in C#. It works fine but one customer insists on using allowlists for EWS access to email. That grants access to apps that supply a User Agent string but how do I include it in the MSGraph header using the SDK calls?
The code is taken from the MS example
var scopes = new[] { "User.Read","Mail.ReadWrite","Mail.ReadWrite.Shared" };
var options = new TokenCredentialOptions
{
AuthorityHost = AzureAuthorityHosts.AzurePublicCloud
};
var userName = strAccount;
var password = strPWD ;
var userNamePasswordCredential = new UsernamePasswordCredential(
userName, password, tenantId, theClientId, options);
var graphClient = new GraphServiceClient(userNamePasswordCredential, scopes);
try
{
rootFolder = await graphClient.Me.MailFolders["msgfolderroot"]
.Request()
.GetAsync();
}..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请注意,V5的此更改
是通过标头,不再使用标题类。使用RequestConfiguration修饰符添加标题如下
Note this change in v5
To pass headers, the HeaderOption class is no longer used. Headers are added using the requestConfiguration modifier as follows
最终发现了GitHubs文档的答案,尽管确实进行了一些实验,发现标题选项名称为“用户代理”
您创建一个选项列表并添加在用户代理选项中
,然后每个.request()调用必须将选项作为参数
Found the answer from the GitHubs docs eventually although it did take some experimentation finding out that the header option name is "User-Agent"
You create an options list and add in the user agent option
Then every .Request() call has to have the options as a parameter e.g.