use*_*125 2 microsoft-graph-api
Graph API Send Email文档指出我可以在同一个 sendMail 操作调用中包含文件附件。有人能够提供一个示例代码,说明如何使用 me/sendmail 以及生成的文件附件(内容存储在内存流中)来实现这一点吗?
一种选择是使用Microsoft Graph .NET SDK ,我在另一个Stack Overflow 答案中找到了此示例代码。
// 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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3972 次 |
| 最近记录: |