gpt4 book ai didi

c# - Microsoft.Graph 发送带有附件的邮件

转载 作者:行者123 更新时间:2023-12-01 23:20:31 24 4
gpt4 key购买 nike

using Microsoft.Graph
IMessageAttachmentsCollectionPage Message.Attachments

我似乎无法让它获取 FileAttachment.ContentBytes 中的任何“ContentBytes”。

我的示例来自 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 上的示例即可解决此问题,请参见下文:

// 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();

关于c# - Microsoft.Graph 发送带有附件的邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42374501/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com