gpt4 book ai didi

c# - 使用 Microsoft Graph API 获取 Outlook 中的所有消息

转载 作者:行者123 更新时间:2023-12-05 05:31:48 26 4
gpt4 key购买 nike

我对适用于 C# 代码的 Microsoft Graph API 有疑问。是否可以获取我在 Outlook 中的所有邮件?

我找到了一篇好文章,但我的问题仍然没有得到答案。文章:

Get all email message using Microsoft Graph API in c#

(已更新)我找到了一个关于如何连接到 Microsoft Graph 的好视频:https://www.youtube.com/watch?v=acnFrkBL1kE&ab_channel=Microsoft365Developer

我还有同样的问题。我可以收到 1000 封电子邮件。有什么方法可以从我的 Outlook 中获取所有邮件吗?它们应该来 self 所有的文件夹。

我的调用 1000 条消息的新代码:

public async Task<(IEnumerable<Message> Messages, string NextLink)> GetUserMessagesPage(
string nextPageLink = null, int top = 1000)
{
IUserMessagesCollectionPage pagedMessages;

if(nextPageLink == null)
{
pagedMessages = await _graphServiceClient.Me.Messages.Request().Select(msg => new
{
msg.Subject,
msg.BodyPreview,
msg.ReceivedDateTime
}).OrderBy("receivedDateTime desc").Top(1000).GetAsync();
}
else
{
var messagesCollectionRequest = new UserMessagesCollectionRequest(nextPageLink, _graphServiceClient, null);
pagedMessages = await messagesCollectionRequest.GetAsync();
}
return (Messages: pagedMessages, NextLink: GetNextLink(pagedMessages));
}

(更新)我也试过这个:

pagedMessages = await _graphServiceClient.Users["email@.com"].Messages.Request().Select(msg => new { msg.Subject}).Top(1000).GetAsync();

messages.AddRange(pagedMessages.CurrentPage);
while (pagedMessages.NextPageRequest != null)
{
pagedMessages = await pagedMessages.NextPageRequest.GetAsync();
messages.AddRange(pagedMessages.CurrentPage);
}

这里提到了:https://github.com/microsoftgraph/microsoft-graph-docs/blob/main/api-reference/beta/api/user-list-messages.md

最佳答案

发件人:Microsoft Graph REST API - Get message Documentation

There are two scenarios where an app can get a message in anotheruser's mail folder:

  • If the app has application permissions, or,
  • If the app has the appropriate delegated permissions from one user, and another user has shared a mail folder with that user, or,has given delegated access to that user. See details and anexample.

Permissions

One of the following permissions is required to call this API. Tolearn more, including how to choose permissions, seePermissions.

  1. Delegated (work or school account) - Permissions: Mail.ReadBasic, Mail.Read

  2. Delegated (personal Microsoft account) - Permissions: Mail.ReadBasic, Mail.Read

  3. Application - Permissions: Mail.ReadBasic.All, Mail.Read

关于c# - 使用 Microsoft Graph API 获取 Outlook 中的所有消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74286801/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com