c# - 发送带有大于 4MB 附件的电子邮件
问题描述
从以下代码中检索令牌
var token = await GetAccessToken();
GraphServiceClient graphServiceClient =
new GraphServiceClient($"{graphApi}/v1.0",
new DelegateAuthenticationProvider(async(requestMessage) =>
{
requestMessage.Headers.Authorization =
new AuthenticationHeaderValue("Bearer", token);
})
);
使用 App 权限发送电子邮件
graphServiceClient.Users[fromAddress]
.SendMail(message, false)
.Request()
.PostAsync().Wait();
并且附件是在动态创建时附加的
attachments.Add(new FileAttachment
{
ODataType = "#microsoft.graph.fileAttachment",
ContentBytes = System.IO.File.ReadAllBytes(getAttachmentLocation() + attach.Name),
ContentId = attach.Name,
ContentType = "csv/html",
Name = attach.Name,
IsInline = false
});
现在的问题是当附件大小超过 4MB 时不会触发电子邮件。
有人可以帮助我了解如何解决此问题吗?
我们是否有任何实际增加这个 4MB 或支持附件 > 4 MB 的新版本 Graph 的阈值的东西?
解决方案
要发送较大的消息,您必须创建一个草稿消息,然后添加附件。如果附件大于 3MB,则无法一次发送。使用 UploadSession 代替,如下所述:https ://docs.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=csharp