Microsoft.Graph send mail with attachment(Microsoft.Graph 发送带有附件的邮件)
问题描述
using Microsoft.Graph
IMessageAttachmentsCollectionPage Message.Attachments
我似乎无法获取 FileAttachment.ContentBytes 中的任何ContentBytes".
I can not seem to get this to take any "ContentBytes" which is in the FileAttachment.ContentBytes.
我的示例来自 Microsoft https://github.com/microsoftgraph/aspnet-snippets-样本.
My sample is from Microsoft https://github.com/microsoftgraph/aspnet-snippets-sample.
// Create the message.
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,
HasAttachments = true,
Attachments = new[]
{
new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = contentBytes,
ContentType = contentType,
ContentId = "testing",
Name = "tesing.png"
}
}
};
推荐答案
使用上面来自 GitHub 的示例解决了这个问题,见下文:
Using the sample above from GitHub this is resolved, see below:
// Create the message with attachment.
byte[] contentBytes = System.IO.File.ReadAllBytes(@"C: est est.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();
这篇关于Microsoft.Graph 发送带有附件的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Microsoft.Graph 发送带有附件的邮件
基础教程推荐
- 有没有办法忽略 2GB 文件上传的 maxRequestLength 限制? 2022-01-01
- 将 XML 转换为通用列表 2022-01-01
- rabbitmq 的 REST API 2022-01-01
- 如何在 IDE 中获取 Xamarin Studio C# 输出? 2022-01-01
- 如何激活MC67中的红灯 2022-01-01
- c# Math.Sqrt 实现 2022-01-01
- SSE 浮点算术是否可重现? 2022-01-01
- MS Visual Studio .NET 的替代品 2022-01-01
- 将 Office 安装到 Windows 容器 (servercore:ltsc2019) 失败,错误代码为 17002 2022-01-01
- 为什么Flurl.Http DownloadFileAsync/Http客户端GetAsync需要 2022-09-30