LoginSignup
6
7

More than 5 years have passed since last update.

Microsoft Graph を使ってみよう : メール、予定表、連絡先リソース (Outlook)

Last updated at Posted at 2018-05-22

メールリソース

Microsoft Graph のメールリソースの操作は、Exchange オンラインおよびハイブリッド展開の設置型 Exchange のメールをサポートします。これにより多くの組織のメッセージ処理の自動化やよりリッチな処理を実施することが出来ます。

主なシナリオ

  • メッセージの下書き、送信、転送、返信、更新、削除、読み取り、検索など
  • メールボックスに対する設定
  • メッセージの添付ファイルの操作
  • 自動応答やロケール、タイムゾーン、就業時間の取得
  • 優先受信トレイやメールフォルダに対する操作
  • カテゴリやルールの操作
  • 拡張プロパティ機能

メールリソースの操作

いくつか代表的な操作を以下に紹介します。

メールの作成と送信

POST: https://graph.microsoft.com/v1.0/me/messages

Body
{
    "subject":"Graph より送信",
    "importance":"Low",
    "body":{
        "contentType":"HTML",
        "content":"Graph で <b>簡単に</b> メールを送信できます。"
    },
    "toRecipients":[
        {
            "emailAddress":{
                "address":"manager1@graphdemo01.onmicrosoft.com"
            }
        }
    ]
}

POST: https://graph.microsoft.com/v1.0/me/messages/{id}/send

C#
var mail = await graphClient.Me.Messages.Request().AddAsync(new Message()
{
    Subject = "Graph より送信",
    Importance = Importance.Low,
    Body = new ItemBody()
    {
        ContentType = BodyType.Html,
        Content = "Graph で <b>簡単に</b> メールを送信できます。"
    },
    ToRecipients = new List<Recipient>()
    {
        new Recipient(){
            EmailAddress = new EmailAddress()
            {
                Address = "manager1@graphdemo01.onmicrosoft.com"
            }
        }
    }
});

await graphClient.Me.Messages[mail.Id].Send().Request().PostAsync();

添付ファイルを取得

GET: https://graph.microsoft.com/v1.0/me/messages/{message_id}/attachments/{attachment_id}

C#
await graphClient.Me.Messages["message_id"].Attachments["attachment_id"].Request().GetAsync();

特定ユーザーからのメールを優先フォルダまたはその他に振り分け

以下の例ではマネージャーからのメールを「その他」フォルダに振り分け
POST: https://graph.microsoft.com/v1.0/me/inferenceClassification/overrides

Body
{
  "classifyAs": "other",
  "senderEmailAddress": {
    "address": "manager1@graphdemo01.onmicrosoft.com"
  }
}
C#
await graphClient.Me.InferenceClassification.Overrides.Request().AddAsync(new InferenceClassificationOverride()
{
    ClassifyAs = InferenceClassificationType.Other,
    SenderEmailAddress = new EmailAddress()
    {
        Address = "manager1@graphdemo01.onmicrosoft.com"
    }
});

予定表リソース

Microsoft Graph ではユーザーの予定表からもグループの既定の予定表からも予定を取得できます。

主なシナリオ

  • 予定表の一覧表示、取得、作成、更新、削除
  • 予定の一覧表示、取得、作成、更新、削除
  • 予定メッセージの取得、更新、削除、返信
  • 予定の添付ファイルの操作
  • グループ予定表の操作
  • カテゴリの設定

予定表リソースの操作

いくつか代表的な操作を以下に紹介します。

予定の一覧を取得

GET: https://graph.microsoft.com/v1.0/me/events
GET: https://graph.microsoft.com/v1.0/groups/{id}/events

C#
await graphClient.Me.Events.Request().GetAsync();
await graphClient.Groups["id"].Events.Request().GetAsync();

予定表の一覧を取得

GET: https://graph.microsoft.com/v1.0/me/calendars

C#
await graphClient.Me.Calendars.Request().GetAsync();

アラーム一覧を取得
以下の例では 2018 年 5 月のアラームを取得

GET: https://graph.microsoft.com/v1.0/me/reminderView(startDateTime='2018-05-01',endDateTime='2018-05-31')

C#
await graphClient.Me.ReminderView("2018-05-01","2018-05-31").Request().GetAsync();

連絡先リソース

メールや予定と同様に Exchange (Outlook) より連絡先リソースを操作できます。

主なシナリオ

  • 連絡先の取得、作成、更新、削除
  • 連絡先フォルダの操作
  • カテゴリの操作

連絡先リソースの操作

いくつか代表的な操作を以下に紹介します。

連絡先一覧の取得

GET: https://graph.microsoft.com/v1.0/me/contacts

C#
await graphClient.Me.Contacts.Request().GetAsync();

連絡先の作成

POST: https://graph.microsoft.com/v1.0/me/contacts

Body
{
  "givenName": "ユーザー1",
  "surname": "サンプル",
  "emailAddresses": [
    {
      "address": "sampleuser1@graphdemo01.onmicrosoft.com",
      "name": "サンプルユーザー1"
    }
  ],
  "businessPhones": [
    "+81 xxx-xxxx"
  ]
}
C#
await graphClient.Me.Contacts.Request().AddAsync(new Contact()
{
    GivenName = "ユーザー1",
    Surname = "サンプル",
    EmailAddresses = new List<EmailAddress>()
    {
        new EmailAddress()
        {
                Address = "sampleuser1@graphdemo01.onmicrosoft.com",
                Name = "サンプルユーザー1"
        }
    },
    BusinessPhones = new List<string>() { "+81 xxx-xxxx" }
});

連絡先の削除

DELETE: https://graph.microsoft.com/v1.0/me/contacts/{id}

C#
await graphClient.Me.Contacts["id"].Request().DeleteAsync();

まとめ

Outlook には個人の活動記録が入っているため分析にも使えますし、予定を保存したタイミングで内容を拡充するような使い方も考えられます。是非試してみてください。

目次へ戻る

参照

Microsoft Graph でのメール操作
Microsoft Graph での予定表操作
Microsoft Graph での連絡先操作

6
7
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
6
7