使用uploadsession的Microsoft Graph API无法接收带有附件的电子邮件 &



电子邮件没有收到附件时,我试图使用Uploadsession使用图形API。有人能告诉我为什么会这样吗?我没有收到任何错误。

Message draft = await graphServiceClient.Users["UserID"].Messages.Request().AddAsync(email);
//Message draft = graphServiceClient.Users["UserID"].Mailfolders.Drafts.Messages.Request().AddAsync(email);
var stream = System.IO.File.Open(@"C:attachDYN28_6579332_33242556.csv", System.IO.FileMode.Open, FileAccess.Read, FileShare.None);
var attachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = "DYN28_6579332_33242556.csv",
Size = stream.Length
};
var uploadSession = await graphServiceClient.Users["Userid"].Messages[draft.Id]
.Attachments
.CreateUploadSession(attachmentItem)
.Request()
.PostAsync();
var maxSlicesize = 320 * 1024;
var largeFileUploadTask = new LargeFileUploadTask<FileAttachment>(uploadSession, stream, maxSlicesize);
IProgress<long> progress = new Progress<long>(prog => {
Console.WriteLine($"Uploaded {prog} bytes of {stream.Length} bytes");
});
// Upload the file
var uploadResult = await largeFileUploadTask.UploadAsync(progress);
if (uploadResult.UploadSucceeded)
{
// The ItemResponse object in the result represents the
// created item.
//Console.WriteLine($"Upload complete, item ID: {uploadResult.ItemResponse.Id}");
Console.WriteLine("upload completed");
}
Finally sending email with 

   
await graphServiceClient.Users["userid"].Messages[draft.Id]
.Send()
.Request()
.PostAsync();

在Graph API中单个请求的限制为4MB。要发送较大的附件,您需要首先针对电子邮件消息/日历事件创建一个上传会话,并在此会话的多个请求中上传您的附件。每个较小的POST请求也需要保持在4MB限制以下。

您可以在这里找到更详细的文档和示例演练。

POST https://graph.microsoft.com/v1.0/me/messages/AAMkADI5MAAIT3drCAAA=/attachments/createUploadSession
Content-type: application/json
{
"AttachmentItem": {
"attachmentType": "file",
"name": "flower",
"size": 3483322
}
}

相关内容

最新更新