Recently Microsoft announced that it is possible to send emails with attachments larger than 4MB.
With smaller attachments, we were able to do everything in a single request. Now we must create a draft, upload attachments and then send the file.
I have a working code that sends mail in a single request:
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();
the above code works fine, but when I change the last line to:
Message draft = await graphClient
.Users["test@test.onmicrosoft.com"]
.MailFolders
.Drafts
.Messages
.Request()
.AddAsync(mail);
or to:
Message draft = await graphClient
.Users["test@test.onmicrosoft.com"]
.Messages
.Request()
.AddAsync(mail);
I get an ErrorAccessDenied
error:
Access is denied. Check credentials and try again.
Why would sending email in a single request work but creating a draft fail? Do I need any special permissions?