最近微软宣布可以发送带有大于 4MB 附件的电子邮件。根据文档,我们必须创建草稿,然后是上传会话,上传附件,最后发送邮件。
我可以使用以下代码创建草稿:
var confidentialClientApplication = ConfidentialClientApplicationBuilder
.Create(clientId)
.WithClientSecret(clientSecret)
.WithTenantId(tenant)
.Build();
var authenticationProvider = new ClientCredentialProvider(confidentialClientApplication);
var graphClient = new GraphServiceClient(authenticationProvider);
var email = new Message
{
Body = new ItemBody
{
Content = i + " Works fine! " + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
ContentType = BodyType.Html,
},
Subject = "Test" + (j == 0 ? "" : " " + j),
ToRecipients = recipientList,
Attachments = att
};
Message draft = await graphClient
.Users["test@test.onmicrosoft.com"]
.Messages
.Request()
.AddAsync(mail);
但是当我尝试从文档中提取片段时:
var attachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = "flower",
Size = 3483322
};
await graphClient.Me.Messages["AAMkADI5MAAIT3drCAAA="].Attachments
.CreateUploadSession(attachmentItem)
.Request()
.PostAsync();
我得到这些错误:
- 找不到类型或命名空间名称“AttachmentItem”(您是否缺少 using 指令或程序集引用?)
- 当前上下文中不存在名称“AttachmentType”
- “IMessageAttachmentsCollectionRequestBuilder”不包含“CreateUploadSession”的定义,并且找不到接受“IMessageAttachmentsCollectionRequestBuilder”类型的第一个参数的可访问扩展方法“CreateUploadSession”(您是否缺少 using 指令或程序集引用?)
我添加了对稳定版和 beta 版图形库(Microsoft.Graph、Microsoft.Graph.Beta)的引用(我之前使用过 beta 端点),但我找不到AttachmentItem
.
我已经搜索了 AttachmentItem 的两个存储库(https://github.com/microsoftgraph/msgraph-sdk-dotnet、https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet),但我什么也没找到.
发送带有大附件的邮件是一项相当新的功能(文档来自 2019 年 10 月 25 日),但根据文档,这应该得到支持。
文档错了吗?如何创建上传会话并上传附件?我必须手动创建请求吗?或者我可以使用 Microsoft.Graph 库吗?
我只看到CreateUploadSession
Drive - https://github.com/microsoftgraph/msgraph-sdk-dotnet/search?q=CreateUploadSession&unscoped_q=CreateUploadSession