最近微软宣布可以发送带有大于 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
};
await graphClient
.Users["test@test.onmicrosoft.com"]
.SendMail(email, true)
.Request()
.WithMaxRetry(5)
.PostAsync();
上面的代码工作正常,但是当我将最后一行更改为:
Message draft = await graphClient
.Users["test@test.onmicrosoft.com"]
.MailFolders
.Drafts
.Messages
.Request()
.AddAsync(mail);
或者:
Message draft = await graphClient
.Users["test@test.onmicrosoft.com"]
.Messages
.Request()
.AddAsync(mail);
我收到一个ErrorAccessDenied
错误:
访问被拒绝。检查凭据并重试。
为什么在单个请求中发送电子邮件但创建草稿会失败?我需要任何特殊权限吗?