I'm using Microsoft-Graph API version 1.4 and trying to send mail with multiple attachments (with size greater then 4MB) using following code..
val address = EmailAddress()
address.address = "[email protected]"
val recipient = Recipient()
recipient.emailAddress = address
val message = MyMessage()
message.subject = "Test E-Mail"
message.body = getItemBody()
message.toRecipients = Collections.singletonList(recipient)
val att = FileAttachment()
att.contentBytes = File("/home/user/file.pdf").readBytes()
att.contentType = "text/pdf"
att.name = "file.pdf"
att.oDataType = "#microsoft.graph.fileAttachment"
val att2 = FileAttachment()
att2.contentBytes = "hello there! from second file".toByteArray(StandardCharsets.UTF_8)
att2.contentType = "text/plain"
att2.name = "hi2.txt"
att2.oDataType = "#microsoft.graph.fileAttachment"
message.addAttachment(att)
message.addAttachment(att2)
graphClient.me()
.sendMail(message,false)
.buildRequest()
.post();
In response, I'm getting following error..
{
"status": "INTERNAL_SERVER_ERROR",
"exception": "GraphServiceException",
"message": "Error code: BadRequest\nError message: The maximum request length supported is 4MB.\n\nPOST https://graph.microsoft.com/v1.0/me/microsoft.graph.sendMail\nSdkVersion : graph-java-v1.4.0\nAuthorization : Bearer eyJ0eXAiOiJKV1QiLCJub25jZSI[...]\n{\"message\":{\"attachments\":[{\"contentBytes\":\"JVBERi[...]\n\n413 : Request Entity Too Large\n[...]\n\n[Some information was truncated for brevity, enable debug logging for more details]",
"existing": null,
"errorData": null,
"tenant": null
}
Can anyone help me to send a mail with multiple attachment with size greater then 4MB.
Thanks
In order to add multiple attachments at once when their total size exceeds 4MB, you need:
Here is a code sample that does something along those lines
Here is a sample implementation for the callback.