MassifApp.MSGraph 1.3.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MassifApp.MSGraph --version 1.3.1
NuGet\Install-Package MassifApp.MSGraph -Version 1.3.1
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.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MassifApp.MSGraph --version 1.3.1
#r "nuget: MassifApp.MSGraph, 1.3.1"
#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.1

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

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メソッドが追加されました。

詳細

  • アクセストークンの有効期限をあまり気にしないようにできます(期限切れは自動で再取得)。
  • 注意点にも記載しましたが、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 = "新しいカフェがオープンしたよ。"
};
builder.AddToRecipient("bar@example.com");
builder.AddAttachment("hoge.pdf", "application/pdf")
MailContent mail = builder.Build();
//メール送信
await client.SendMail("https://graph.microsoft.com/v1.0/users/foo@example.com/sendMail", 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クラスへプロパティ追加

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 242 10/30/2023
1.3.2 332 11/28/2022
1.3.1 303 11/24/2022
1.3.0 304 11/22/2022
1.2.0 398 10/15/2022
1.1.0 372 9/17/2022
1.0.1 377 9/5/2022