发送带有大于 4MB 附件的电子邮件

时间:2021-03-04 10:00:44

标签: c# microsoft-graph-api microsoft-graph-sdks microsoft-graph-mail

从下面的代码中检索令牌

var token = await GetAccessToken();
GraphServiceClient graphServiceClient =
  new GraphServiceClient($"{graphApi}/v1.0",
    new DelegateAuthenticationProvider(async(requestMessage) =>
    {
      requestMessage.Headers.Authorization =
        new AuthenticationHeaderValue("Bearer", token);
    })
  );

使用应用权限发送电子邮件

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 或支持大于 4MB 附件的 Graph 的阈值?

1 个答案:

答案 0 :(得分:0)

要发送较大的邮件,您必须创建邮件草稿,然后添加附件。 如果附件大于 3MB,则不能一次发送。改用 UploadSession,如下所述:https://docs.microsoft.com/en-us/graph/sdks/large-file-upload?tabs=csharp

相关问题