mcpField
M
m365

m365

github.com/pietz生産性197 回インストール15 週間前に更新
リポジトリ

m365 について

m365 CLIとMicrosoft Graphを通じて、OutlookメールとMicrosoft 365カレンダーを操作するスキルです。メールや予定の照会に加え、書き込み操作では事前にユーザーの確認を求めます。

主な機能

  1. 01メールの一覧・閲覧・検索・移動
  2. 02メールの送信と返信
  3. 03カレンダー予定の照会と管理
  4. 04JSON出力とJMESPathフィルタリング
  5. 05接続と認証の確認

活用シーン

  1. 01本文や送信者からメールを検索
  2. 02メールを確認またはアーカイブ
  3. 03指定期間の予定を一覧表示
  4. 04カレンダー予定を作成または削除

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/pietz/skills --skill m365

インストール後、Claude Code で/m365を入力して読み込まれたか確認します。

同梱ファイルsetup.md

詳細

CLI for Microsoft 365 を使用した Microsoft 365

このスキルでは、m365 CLI(CLI for Microsoft 365)を使用して、Microsoft Graph API 経由で Outlook のメールとカレンダーを操作します。macOS、Linux、Windows のクロスプラットフォームで動作します。

接続の確認

何かを行う前に、次の 2 つのコマンドを並行して実行します。

m365 status --output json
m365 connection list --output json

アクティブな接続の "authType": "secret" がすでに設定されている場合は、タスクに進みます。

アクティブな接続の認証タイプが異なる場合(例:deviceCode)、connection list で "authType": "secret" の非アクティブな接続がないか確認します。ある場合は、それを有効にします。

m365 connection use --name "<connection-name>"

secret 接続が存在しない場合に限り、./setup.md(このファイルからの相対パス)を読み、セットアップ手順に従います。

ユーザーのメールボックスを対象とするすべてのコマンドでは、--userName <upn>(組み込みコマンド)または Graph API の URL にユーザープリンシパル名を指定する必要があります。UPN(例:[email protected])が不明な場合は、ユーザーに確認してください。

重要な注意事項

  • 書き込み操作(メールの送信、イベントの作成/削除)を行う前に、必ずユーザーの確認を得てください。
  • CLI にはメール用の組み込みコマンドがありますが、カレンダーイベント用のコマンドはありません。カレンダーの操作には、Graph API の URL を指定して m365 request を使用してください。
  • 機械可読な出力には --output json を使用します。フィールドの絞り込みには --query(JMESPath)を使用します。
  • すべてのコマンドで -h/--help が使用できます。コマンドを確認するには、m365 <command group> --help を使用します。

メール

メッセージの一覧表示
m365 outlook message list --folderName inbox --userName <upn> --output json

# With date range (endTime must be in the past)
m365 outlook message list --folderName inbox --userName <upn> \
  --startTime "2026-02-01T00:00:00Z" --endTime "2026-02-15T00:00:00Z" --output json

# Compact output with JMESPath
m365 outlook message list --folderName inbox --userName <upn> --output json \
  --query "[].{subject:subject,from:from.emailAddress.address,received:receivedDateTime,isRead:isRead}"

フォルダー名:inbox、drafts、sentitems、deleteditems、junkemail、archive。--folderId も使用できます。

特定のメッセージを読む
m365 outlook message get --id <message-id> --userName <upn> --output json
メールを検索する(Graph API 経由)

組み込みの message list は検索に対応していません。$search または $filter を指定して m365 request を使用します。

# Full-text search (subject, body, sender, etc.)
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/messages?\$search=%22keyword%22&\$select=subject,from,receivedDateTime&\$top=10" --method get --output json

# Filter by sender
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/messages?\$filter=from/emailAddress/address eq '[email protected]'&\$select=subject,receivedDateTime&\$top=10" --method get --output json

注:$search と $orderby は併用できません。$search の結果は関連度順に並べられます。

メールフォルダーの一覧表示
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/mailFolders?\$select=displayName,id,totalItemCount,unreadItemCount" --method get --output json
メールを送信する
# Plain text
m365 outlook mail send --subject "Subject" --to "[email protected]" \
  --sender "<upn>" --bodyContents "Message body" --output json

# HTML with multiple recipients
m365 outlook mail send --subject "Subject" --to "[email protected],[email protected]" \
  --cc "[email protected]" --sender "<upn>" \
  --bodyContents "<p>HTML body</p>" --bodyContentType HTML --output json

# With attachment (max 3 MB per attachment)
m365 outlook mail send --subject "Subject" --to "[email protected]" \
  --sender "<upn>" --bodyContents "See attached." \
  --attachment "/path/to/file.pdf" --output json

# Send from shared mailbox
m365 outlook mail send --subject "Subject" --to "[email protected]" \
  --mailbox "[email protected]" --sender "<upn>" \
  --bodyContents "Sent from shared mailbox" --output json
メールに返信する(Graph API 経由)

CLI には組み込みの返信コマンドがありません。Graph API の返信エンドポイントを指定して m365 request を使用します。

# Reply to sender only (plain text comment)
cat > /tmp/m365_reply.json << 'EOF'
{
  "comment": "Thanks, that works for me!"
}
EOF

m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/messages/<message-id>/reply" \
  --method post --body @/tmp/m365_reply.json --content-type "application/json"

# Reply all
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/messages/<message-id>/replyAll" \
  --method post --body @/tmp/m365_reply.json --content-type "application/json"

# Reply with HTML body and additional recipients
cat > /tmp/m365_reply.json << 'EOF'
{
  "message": {
    "toRecipients": [
      {"emailAddress": {"address": "[email protected]", "name": "Extra Recipient"}}
    ]
  },
  "comment": "<p>Replying with <b>HTML</b> content.</p>"
}
EOF

m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/messages/<message-id>/reply" \
  --method post --body @/tmp/m365_reply.json --content-type "application/json"

Graph API がスレッドの管理、元のメッセージの引用、宛先の自動設定を行います。返信本文には comment を使用します。必要に応じて message オブジェクトを含め、宛先を追加または上書きできます。成功すると、本文なしで 202 Accepted が返されます。Mail.Send 権限が必要です。

メッセージの移動/アーカイブ
m365 outlook message move --id <message-id> \
  --sourceFolderName inbox --targetFolderName archive --output json

カレンダー

カレンダー操作では、Microsoft Graph API のエンドポイントを指定して m365 request を使用します。POST/PUT/PATCH リクエストでは、JSON 本文を一時ファイルに書き込み、--body @/path/to/file.json --content-type "application/json" を指定します。

カレンダーの一覧表示
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/calendars?\$select=name,id,canEdit,isDefaultCalendar" --method get --output json
今後のイベントを一覧表示する(カレンダービュー)

日付範囲内のイベントには calendarView を使用します(繰り返しイベントを展開します)。

m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/calendarView?\$select=subject,start,end,location,organizer,isAllDay&startDateTime=2026-02-17T00:00:00Z&endDateTime=2026-02-24T00:00:00Z&\$orderby=start/dateTime" --method get --output json
イベントの詳細を取得する(出席者を含む)
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/events/<event-id>?\$select=subject,start,end,location,organizer,attendees,body,onlineMeeting" --method get --output json
イベントを検索する
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/events?\$filter=contains(subject,'keyword')&\$select=subject,start,end&\$top=10" --method get --output json
イベントを作成する

イベントの JSON を一時ファイルに書き込み、その後 POST します。

cat > /tmp/m365_event.json << 'EOF'
{
  "subject": "Meeting Title",
  "start": {"dateTime": "2026-03-01T14:00:00", "timeZone": "Europe/Berlin"},
  "end": {"dateTime": "2026-03-01T15:00:00", "timeZone": "Europe/Berlin"},
  "location": {"displayName": "Conference Room"},
  "attendees": [
    {"emailAddress": {"address": "[email protected]", "name": "Name"}, "type": "required"}
  ],
  "body": {"contentType": "text", "content": "Agenda: ..."}
}
EOF

m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/events" \
  --method post --body @/tmp/m365_event.json --content-type "application/json" --output json
イベントを削除する
m365 request --url "https://graph.microsoft.com/v1.0/users/<upn>/events/<event-id>" \
  --method delete

ヒント

  • ページ分割された結果には @odata.nextLink が含まれます。次のページを取得するには、その URL を m365 request に渡します。
  • 特定のフィールドを抽出するには --query(JMESPath)を使用します:--query "[].{subject:subject,from:from.emailAddress.address}"。
  • Graph API リクエストでは、シェルで $ をエスケープするために \$ を使用します。
  • $top は結果数を制限します:$top=5 は最大 5 件を返します。
  • Graph API の日時は UTC です。現地時間を指定するには、イベントの開始時刻と終了時刻に timeZone を指定します。

コメント