// Create the message with attachment.
byte[] contentBytes = System.IO.File.ReadAllBytes("test.xlsx");
string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage();
attachments.Add(new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = contentType,
ContentId = "test",
Name = "test.xlsx"
});
var message = new Message
{
Subject = "こちらは件名です",
Body = new ItemBody
{
ContentType = BodyType.Text,
Content = "こちらは本文です。"
},
ToRecipients = new List<Recipient>()
{
new Recipient
{
EmailAddress = new EmailAddress
{
Address = "meganb@contoso.onmicrosoft.com"
}
}
},
Attachments = attachments
};
//await graphClient.Users["test@outlook.jp"]→アプリケーション認証
//委任認証
await graphClient.Me
.SendMail(message,true)
.Request()
.PostAsync();
参考サイト