1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Power Automateでoutlookメールのカテゴリ取得メモ

Last updated at Posted at 2025-05-22

こんな感じでカテゴリ(ラベル)設定中のメールに対して、"じゃがいも"カテゴリや"美術館"カテゴリなど任意のカテゴリのメールを取得します。

CleanShot 2025-05-23 at 00.27.48.png

一旦の完成イメージのフロー

CleanShot 2025-05-23 at 00.52.03.png

クエリパラメータ

STEP1. メール取得

OutlookのHTTP要求の送信モジュールを使って情報を取得します。

URLにはGraph APIを指定します。

https://graph.microsoft.com/v1.0/me/mailFolders/Inbox/messages?$select=subject,receivedDateTime,categories&$top=10

CleanShot 2025-05-22 at 23.48.43.png
CleanShot 2025-05-22 at 23.52.46.png

{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('xxxxxxx')/mailFolders('Inbox')/messages(subject,receivedDateTime,categories)",
  "value": [
      {
          "@odata.etag": "W/\"xxxxxxxx\"",
          "id": "xxxxxx",
          "categories": [],
          "receivedDateTime": "2025-05-22T06:07:39Z",
          "subject": "結果確認メール(Automate)"
      },
      {
          "@odata.etag": "W/\"xxxxxxxx\"",
          "id": "xxxxxxxx",
          "categories": [],
          "receivedDateTime": "2025-05-22T06:07:19Z",
          "subject": "Text Recognition results"
      }
  ]
}

STEP2. カテゴリを文字列化する

json()関数を使うことでカテゴリの情報を文字列として扱うことができます。

join(<ここに動的コンテンツを指定>,',')という使い方になり、画像のように式を入れるフォームでBody Categoriesを指定します。

join(items('For_each')?['categories'],',')

CleanShot 2025-05-23 at 00.45.51.png

CleanShot 2025-05-23 at 00.46.13.png

Tips: 文字列追加だと

条件分岐で"じゃがいも"というタグがあるメールの情報に対して処理をしたいときに、カテゴリの文字列変数から条件分岐をしようとして"文字列変数に追加"のモジュールを選んで実行していました。

CleanShot 2025-05-23 at 00.27.48.png

...が、これだと変数に追加されていってしまいます。

じゃがいも返信来てない,じゃがいも美術館,じゃがいも返信来てない,Blue category返信来てない,Blue category返信来てない,Blue category返信来てない,Blue category返信来てない,Blue category / じゃがいもカテゴリ

CleanShot 2025-05-23 at 00.46.58.png

全てのカテゴリ情報が連結されちゃうので"じゃがいも"のカテゴリではないメールにもじゃがいもカテゴリ判定になってしまっていました。

STEP3.

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?