0
Graph API Send Email文檔聲明我可以在同一個sendMail動作調用中包含文件附件。有人能夠提供一個示例代碼,說明如何使用me/sendmail和附件從生成內容存儲在內存流中的文件中實現這一點。圖形API SendMail帶附件,使用c#中的REST示例#
Graph API Send Email文檔聲明我可以在同一個sendMail動作調用中包含文件附件。有人能夠提供一個示例代碼,說明如何使用me/sendmail和附件從生成內容存儲在內存流中的文件中實現這一點。圖形API SendMail帶附件,使用c#中的REST示例#
一種選擇是使用Microsoft Graph .NET SDK,我在另一個Stack Overflow answer中找到了此示例代碼。
// Create the message with attachment.
byte[] contentBytes = System.IO.File.ReadAllBytes(@"C:\test\test.png");
string contentType = "image/png";
MessageAttachmentsCollectionPage attachments = new MessageAttachmentsCollectionPage();
attachments.Add(new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = contentType,
ContentId = "testing",
Name = "testing.png"
});
Message email = new Message
{
Body = new ItemBody
{
Content = Resource.Prop_Body + guid,
ContentType = BodyType.Text,
},
Subject = Resource.Prop_Subject + guid.Substring(0, 8),
ToRecipients = recipients,
Attachments = attachments
};
// Send the message.
await graphClient.Me.SendMail(email, true).Request().PostAsync();