Vivek Buddhadev
Vivek Buddhadev

Reputation: 397

Send Mail with mixed sized attachments (> 4MB) using Graph API (version 2.3.2)

I've following list of attachments to send in mail

To send total file size under 4 MB(1MBPDF, 210KBPDF) I can use this approach and To send large file (4MBPDF) I'm using solution provided here

But when I'm trying to send three files (1MBPDF, 210KBPDF, 4MBPDF) together using large file approach (Sample code) I'm getting following error...

com.microsoft.graph.http.GraphServiceException: Error code: ErrorAttachmentSizeShouldNotBeLessThanMinimumSize Error message: Attachment size must be greater than the minimum size.

POST https://graph.microsoft.com/v1.0/me/messages/AAMkAGNhNWJlNjdkLWNkZTUtNDE1Yy1hYzkxLTkyOWI1M2U3NGQzOABGAAAAAAASIVxVSsS8RI-T3F73mdJZBwANqxyKMlQbSqZO439E21_mAAAAAAEPAAANqxyKMlQbSqZO439E21_mAAAVRY2dAAA=/attachments/microsoft.graph.createUploadSession SdkVersion : graph-java/v2.3.2 Authorization : [PII_REDACTED] {"attachmentItem":{"attachmentType":"file","conten[...]

400 : Bad Request [...]

Please let me know if I'm making any mistakes to implement the approach or suggest me any work-around to send multiple attachments mixed in size.

Thanks

Upvotes: 2

Views: 2704

Answers (1)

baywet
baywet

Reputation: 5382

Here is the approach I suggest you take to avoid any issues:

  1. Create a draft email
  2. Upload any attachment <3MB via the add attachment endpoint
  3. Upload any attachment >3MB via the large upload endpoint
  4. Send the email endpoint

With that approach instead of trying to upload the small attachments with the draft email creation, you'll avoid random failures when the total size of base64 encoded small attachments exceeds the maximum size of 4MB per request on Microsoft Graph.

Upvotes: 10

Related Questions