【发布时间】:2021-03-04 02:05:43
【问题描述】:
当我尝试使用 Graph API 使用 Uploadsession 时,未收到带有附件的电子邮件。有人可以帮我理解为什么会这样。我没有收到任何错误。
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:\attach\DYN28_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();
【问题讨论】:
-
如果你有 S3 下载链接,他们有 ~3MB 的限制。
-
作为一种解决方法,您可以使用 SMTP 发送邮件,它没有此限制。
-
或以 ZIP 格式发送
-
我们最近迁移到了图形 API。以前我们使用没有任何限制的 SMTP。什么是 S3 下载链接?
-
能否请您给我有关如何使用图形 API 压缩附件并通过电子邮件发送的代码
标签: microsoft-graph-api microsoft-graph-sdks microsoft-graph-mail