Recently Microsoft announced that it is possible to send emails with attachments larger than 4MB. According to the docs, we must create a draft, then an upload session, upload attachment and finally send the mail.
I am able to create a draft using below code:
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["[email protected]"]
.Messages
.Request()
.AddAsync(mail);
but when I try snippet from the docs:
var attachmentItem = new AttachmentItem
{
AttachmentType = AttachmentType.File,
Name = "flower",
Size = 3483322
};
await graphClient.Me.Messages["AAMkADI5MAAIT3drCAAA="].Attachments
.CreateUploadSession(attachmentItem)
.Request()
.PostAsync();
I get those errors:
- The type or namespace name 'AttachmentItem' could not be found (are you missing a using directive or an assembly reference?)
- The name 'AttachmentType' does not exist in the current context
- 'IMessageAttachmentsCollectionRequestBuilder' does not contain a definition for 'CreateUploadSession' and no accessible extension method 'CreateUploadSession' accepting a first argument of type 'IMessageAttachmentsCollectionRequestBuilder' could be found (are you missing a using directive or an assembly reference?)
I've added references to both stable and the beta version of graph libraries (Microsoft.Graph, Microsoft.Graph.Beta) (I used beta endpoint before) but I can't find AttachmentItem.
I've searched two repos (https://github.com/microsoftgraph/msgraph-sdk-dotnet, https://github.com/microsoftgraph/msgraph-beta-sdk-dotnet) for AttachmentItem but I didn't find anything.
Sending mails with large attachments is quite a new feature (docs are from 25 October 2019), but according to docs this should be supported.
Are the docs wrong? How can I create an upload session and upload attachments? Must I create requests manually? Or can I use Microsoft.Graph library?
I only see CreateUploadSession for Drive - https://github.com/microsoftgraph/msgraph-sdk-dotnet/search?q=CreateUploadSession&unscoped_q=CreateUploadSession