整理 Outlook 邮件Organize Outlook messages

Outlook 允许客户按照自己喜欢的方式整理邮件,可以将所有邮件都留在同一“收件箱”文件夹中,或者在“收件箱”下的树文件夹结构中整理邮件,以满足自己的特定需要。Outlook lets customers organize their messages the way they like it, be it leaving all messages in the same Inbox folder, or organizing messages in a tree-like folder structure under the Inbox to fit their specific needs. 可以方便地对用户整个邮箱或特定文件夹中的邮件进行筛选、搜索或排序You can conveniently filter, search, or sort messages in the user's entire mailbox or in specific folders.

访问邮件文件夹Accessing mail folders

以编程方式,邮件文件夹由 mailFolder 资源表示,“收件箱”是文件夹结构根目录中的一个文件夹。Programmatically, message folders are represented by the mailFolder resource, and the Inbox is one of the folders at the root of the folder structure.

每个 mailFolder 都由其文件夹 ID 标识,并具有可写的 displayName 属性。Each mailFolder is identified by its folder ID, and has a writable displayName property. Outlook 默认情况下会为客户创建其他几个文件夹。Outlook creates a few other folders for customers by default. 可以按文件夹 ID 或其已知的名称引用这些默认文件夹。You can reference these default folders by their folder IDs, or by their well-known names. 有关可用的已知文件夹名称的列表,请参阅 mailFolder 资源类型For a list of available well-known folder names, see mailFolder resource type.

对于自定义的非默认文件夹,如果知道其文件夹路径,则可先使用 /users/{id}/mailfolders 快捷方式进入根级别并获取所有顶级文件夹,以访问该文件夹:For a custom, non-default folder, if you know its folder path, you can access the folder by first using the /users/{id}/mailfolders shortcut to get to the root level and get all the top level folders:

GET https://graph.microsoft.com/v1.0/users/{id}/mailFolders

然后,在浏览文件夹树的每个级别时指定相应的文件夹 ID ({folder_id}):Then, specify the appropriate folder ID ({folder_id}) as you navigate each level of the folder tree:

GET https://graph.microsoft.com/v1.0/users/{id}/mailFolders/{folder_id}/childfolders

重复此操作,直到最终到达树中的自定义文件夹。Repeat until you finally get to the custom folder in the tree.

创建和整理文件夹树Creating and organizing the folder tree

可以在“收件箱”下创建邮件文件夹,或者作为其他文件夹的子文件夹You can create mail folders under the Inbox, or as child folders of other folders. 创建、复制移动文件夹及其内容时,Outlook 会更新所涉及文件夹的只读 parentFolderIdchildFolderCount 属性。When you create, copy, or move a folder and its contents, Outlook updates the read-only parentFolderId and childFolderCount properties of the involved folders. 当文件夹的内容复制或移动到另一个文件夹时,默认情况下,内容的各个条目 ID 也会更改。When the contents of a folder are copied or moved to another folder, by default, the individual entry IDs of the contents also change.

在内容级别,totalItemCountunreadItemCount 分别告诉你邮件文件夹中的项目数和未读项目数。At the contents level, totalItemCount and unreadItemCount respectively tell you the number of items and number of unread items in a mail folder. 在子文件夹级别,可以列出“收件箱”或任何其他文件夹下的子文件夹At the child folders level, you can list the child folders under the Inbox or any other folder. childFolderCount 属性表示直接子文件夹的数量。The childFolderCount property represents the number of immediate child folders.

请注意,Outlook 邮件文件夹可以包含邮件和非邮件项目,例如事件和联系人。Be aware that Outlook mail folders can contain messages and non-message items such as events and contacts. 通常,Outlook 文件夹可以包含异类项目。In general, Outlook folders can contain heterogeneous items.

使用规则自动复制或移动邮件Using rules to automate copying or moving messages

Outlook 允许客户设置规则,以在满足某些预确定的条件时自动对传入邮件执行特定操作。Outlook lets customers set up rules to automate specific actions on incoming messages when some pre-determined conditions are met. 可以为“收件箱”创建一个规则作为 messageRule,以在特定条件下将邮件复制或移动到特定文件夹。You can create a rule for the Inbox as a messageRule to copy or move a message to a specific folder upon certain conditions. 条件是 messageRulePredicatesConditions are messageRulePredicates. 它们可以包括包含特定文本的邮件主题或正文、从某些电子邮件地址发送的邮件或标记为重要的邮件等等。They can include the message subject or body containing certain text,the message sent from certain email addresses, or the message marked important, and so on.

仅将关注的邮件定向到“重点收件箱”Directing only the messages you care for to the Focused Inbox

“重点收件箱”可让客户训练 Outlook 在“重点”**** 选项卡中仅显示来自关注发件人传入的邮件,其余邮件则在“其他”**** 选项卡中。最初,Outlook 的分类系统以默认方式整理“收件箱”邮件。Focused Inbox lets customers train Outlook to show only the incoming messages from senders you care for in the Focused tab, and the rest in the Other tab. Initially, Outlook's classification system organizes Inbox messages in a default way. 随着时间的推移,可以通过用户界面或以编程方式对系统进行更正和训练。Over time, you can correct and train the system through the user interface or programmatically. 使用“重点收件箱”越多,分类系统就能越好推断出要在“重点”**** 选项卡中查看的传入邮件。The more you use the Focused Inbox, the better the classification system can infer which incoming message you want to see in the Focused tab.

通过编程方式,可以更新邮件inferenceClassification 属性,以指示要在“重点”**** 还是“其他”**** 选项卡中查看邮件。这是特定邮件的一次性指定。Programmatically, you can update the inferenceClassification property of a message to indicate whether you want to see the message in the Focused or Other tab. This is a one-off designation for a specific message. 另一方面,如果希望始终在“重点”**** 选项卡或“其他”**** 选项卡中查看来自特定发件人的邮件,则可以为 Outlook 设置指令If, on the other hand, you want to see messages from a specific sender always in the Focused tab or Other tab, you can set an instruction for Outlook. 每条指令都是一个 inferenceClassificationOverride 实例,指定发件人的姓名,并指定来自该发件人的邮件始终为 focusedotherEach instruction is an inferenceClassificationOverride instance specifying the sender's name and your designation for messages from that sender to be always focused or other. 对用户“重点收件箱”的每条用户指令都存储为 user 对象的一个 inferenceClassificationOverride 实例集合。Each user's instructions for the user's Focused Inbox are stored as a collection of inferenceClassificationOverride instances on the user object.

在应用中使邮件和邮件文件夹保持最新Keeping messages and mail folders up to date in apps

应用通常必须同步并在应用本地存储中使用户的邮件数据保持最新。Apps often have to synchronize and keep a user's mail data up-to-date in the app local store. Microsoft Graph 允许订阅更改通知,以在数据更改时得到通知,并在发生更改时立即查询实际更改。Microsoft Graph lets you subscribe to change notifications to get notified when data changes, and query for actual changes as soon as they happen.

在发生更改时,通知将通过 webhooks 异步传递,从而节省应用频繁进行轮询的开销。Notifications are delivered via webhooks asynchronously when the changes happen, saving apps the overhead to poll frequently. 可以订阅有关添加、更新或删除用户邮件数据的更改通知You can subscribe to change notifications about additions, updates, or deletions to a user's mail data. 例如,可以创建对特定文件夹(即 /me/mailFolders('{folderId'}'))或根级别(即 /me/messages)中邮件的订阅。For example, you can create a subscription to messages in a specific folder (i.e., /me/mailFolders('{folderId'}')), or at the root level (i.e., /me/messages). 订阅会指定一个 notificationUrl,Microsoft Graph 将在发生所请求类型的更改时在其中通知应用。The subscription specifies a notificationUrl where Microsoft Graph notifies the app when the requested types of changes happen.

若要初始同步用户的邮箱,首先,请对从根级别开始的邮件文件夹执行增量查询,以同步所有邮件文件夹,然后对每个文件夹中的邮件执行增量查询,以同步各个邮件。To initially synchronize a user's mailbox, first do delta query for mail folders starting at the root level to synchronize all mail folders, followed by delta query for messages in each folder to synchronize individual messages.

若要查找在未通过任何通知读取整个资源的情况下更改的确切实体,可以使用增量查询跟踪重要更改,并将本地存储与这些更改同步。To find the exact entities that have been changed without reading the entire resource with every notification, you can use delta query to track those changes that matter to you, and synchronize your local store with those changes. 可以跟踪特定文件夹中的邮件更改You can track changes to messages in a specific folder. 还可以跟踪根级别(即 /me/mailfolders)的邮件文件夹更改。You can also track changes to mail folders at the root level (i.e., /me/mailfolders).

后续步骤Next steps

详细了解以下信息:Find out more about: