MassifApp.MSGraph 1.3.3.2

dotnet add package MassifApp.MSGraph --version 1.3.3.2
NuGet\Install-Package MassifApp.MSGraph -Version 1.3.3.2
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MassifApp.MSGraph" Version="1.3.3.2" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MassifApp.MSGraph --version 1.3.3.2
#r "nuget: MassifApp.MSGraph, 1.3.3.2"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MassifApp.MSGraph as a Cake Addin
#addin nuget:?package=MassifApp.MSGraph&version=1.3.3.2

// Install MassifApp.MSGraph as a Cake Tool
#tool nuget:?package=MassifApp.MSGraph&version=1.3.3.2

MassifApp.MSGraph

概要

Microsoft Graph向けラッパークラスです。
Graphで使用するトークンの取り扱いを若干簡略化します。
Graphの全APIに対応しているかは保証されていません。

注意点

System.Net.Http.HttpClientクラスのインスタンスをプライベート変数として保持しています。そのため、同クラスのデザインパターン適用を推奨します。

ver 1.3

  • HttpGraphClientクラスからGetStringAsyncメソッドが削除されました。代わりにGetAsyncメソッドを使用してください。
  • HttpGraphClientクラスのGetAsync<T>メソッドの戻り値Tはnull許容(Task<T?>)となり、new()制限が削除されています。
  • HttpGraphClientクラスへSendAsyncメソッドが追加されました。

ver 1.3.1

  • MessageResourceクラスのReveivedDateTimeプロパティとSentDateTimeプロパティに値を設定しないと、GraphAPIのメール送信時に400 Bad Reuestが返ってきます。対処方法として、GraphAPIを呼び出す前に、DateTime.Nowなど事前に値を設定することで正常に送信することができます。

ver 1.3.2

  • MessageResourceクラスのReveivedDateTimeプロパティとSentDateTimeプロパティに、初期値でDateTime.Nowを設定するようにしました。

ver 1.3.3.2

  • MessageResourceクラスのSenderプロパティ追加に伴い、MailBuilderクラスにFromプロパティ及び、Senderプロパティを追加しました。

詳細

  • アクセストークンの有効期限をあまり気にしないようにできます(期限切れは自動で再取得)。
  • 注意点にも記載しましたが、HttpClientクラスのインスタンスを内部で保持しています。リクエスト毎にインスタンス化することは避けてください。
  • クラス継承が本来の姿なのかもしれません。継承すると仮想メソッドのオーバライドが禁止されているのでインスタンス保持を選択しましたが・・・

Outlook GrapAPIを呼び出してメール一覧を取得:
using MassifApp.MSGraph;

//クライアントインスタンス生成
string clientId = "略";
string clientSecret = "略";
string tenantId = "略";
MSGraphToken token = new(clientId, clientSecret, tenantId)
HttpGraphClient client = new(token);
//要求を実行
//メール一覧は、メッセージID、送信元、件名のみ含む
string messages = client.GetAsync("https://graph.microsoft.com/v1.0/users/foo@example.com/mailFolders/inbox/messages?$select=id,from,subject")
Outlook GraphAPIを呼び出して添付ファイル付メール送信:
using MassifApp.MSGraph;

//クライアント生成
string clientId = "略";
string clientSecret = "略";
string tenantId = "略";
MSGraphToken token = new(clientId, clientSecret, tenantId)
HttpGraphClient client = new(token);
//メール設定
MailBuilder builder = new()
{
    Subject = "ランチ一緒にどう?",
    Body = "新しいカフェがオープンしたよ。",
    From = "foo@example.com"
};
builder.AddToRecipient("bar@example.com");
builder.AddAttachment("hoge.pdf", "application/pdf")
string url = $"https://graph.microsoft.com/v1.0/users/{builder.User}/sendMail";
MailContent mail = builder.Build();
//メール送信
await client.SendMail(url, mail)

問合せ先

使用方法や実装手順等、あるいは開発案件についてもご相談を承っていますので、お気軽にお問い合わせください。

マシフデジタルソリューション合同会社 https://www.massif.jp

更新履歴

ver. 1.0.1
  • 新規アップロード
ver. 1.1.0
  • Outlookに関連したリソースクラスを追加
ver. 1.2.0
  • MailBuilderクラスを追加
  • readmeの例をMailBuilder使用のコードに差替え
ver. 1.3.0
  • HttpGraphClientクラスの拡張メソッドを追加
  • readmeの例を差替え
ver. 1.3.1
  • MessageResourceクラスへプロパティ追加
ver. 1.3.2
  • MessageResourceクラスのプロパティへ初期値設定
ver. 1.3.3.2
  • MailBuilderクラスへFromプロパティ、Senderプロパティ追加
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.3.3.2 237 10/30/2023
1.3.2 329 11/28/2022
1.3.1 301 11/24/2022
1.3.0 302 11/22/2022
1.2.0 397 10/15/2022
1.1.0 371 9/17/2022
1.0.1 376 9/5/2022