title: Send Mail With Multiple Attachments (Size < 4 MB) Using Graph API Version 2.3.2
body: <p>I'm trying to send mail with multiple attachments (Sum of size is &lt; 4MB) using Graph API version 2.3.2. Please find the following code snippet for the same.</p>
  <pre><code>public static void main(String[] a){
      try {
          TestBase testBase = new TestBase();
          Message message = getMessage();
          message.hasAttachments = true;
          AttachmentCollectionResponse response = new AttachmentCollectionResponse();
          response.value = Arrays.asList(
                  getFileAttachment(&quot;/home/user/Downloads/3MBPDF.pdf&quot;),
                  getFileAttachment(&quot;/home/user/Downloads/20KBPDF.pdf&quot;));
          message.attachments = new AttachmentCollectionPage(response, null);
          testBase.graphClient.me().sendMail(message, true).buildRequest().post();
      }catch (Exception e){
          e.printStackTrace();
      }
  }
  
  private static Message getMessage() {
      Message message = new Message();
      java.util.List&lt;String&gt; emails = Arrays.asList(&quot;vivektest@gmail.com&quot;);
      java.util.List&lt;Recipient&gt; listReceipient = new ArrayList&lt;&gt;();
      for(String email : emails) {
          EmailAddress emailAddress = new EmailAddress();
          emailAddress.address = email;
          Recipient recipient = new Recipient();
          recipient.emailAddress = emailAddress;
          listReceipient.add(recipient);
      }
      message.body = getItemBody();
      message.toRecipients = listReceipient;
      message.subject = &quot;Test Message&quot;;
      message.id = &quot;1234&quot;;
      return message;
  }
  
  private static ItemBody getItemBody() {
      ItemBody itemBody = new ItemBody();
      itemBody.content = &quot;&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt; test body &lt;/body&gt;&lt;/html&gt;&quot;;
      itemBody.contentType = BodyType.HTML;
      return itemBody;
  }
  
  private static FileAttachment getFileAttachment(String path) throws Exception{
      FileAttachment fileAttachment = new FileAttachment();
      File pdfFile = new File(path);
      InputStream fileStream = new FileInputStream(pdfFile);
      fileAttachment.name = pdfFile.getName();
      fileAttachment.contentBytes = getByteArray(fileStream);
      fileAttachment.oDataType = &quot;#microsoft.graph.fileAttachment&quot;;
      fileAttachment.size = Math.toIntExact((pdfFile.length() / 1024) / 1024);
      System.out.println(&quot;FileSize::: &quot;+fileAttachment.size);
      fileAttachment.id=&quot;521&quot;;
      return fileAttachment;
  }
  
  public static byte[] getByteArray(InputStream in) {
      try {
          ByteArrayOutputStream buffer = new ByteArrayOutputStream();
          int nRead;
          byte[] data = new byte[16384];
          while ((nRead = in.read(data, 0, data.length)) != -1) {
              buffer.write(data, 0, nRead);
          }
          buffer.flush();
          return buffer.toByteArray();
      } catch (Exception e) {
          e.printStackTrace();
      }
      return null;
  }
  </code></pre>
  <p>I've double check the size of the files.
  3MBPDF.pdf = 3.6 MB
  20KBPDF.pdf = 20 KB</p>
  <p>Total size is not greater then 4 MB but still its returning following error</p>
  <blockquote>
  <p>SEVERE: Throwable detail:
  com.microsoft.graph.http.GraphServiceException: Error code: BadRequest
  Error message: The maximum request length supported is 4MB.</p>
  <p>POST <a href="https://graph.microsoft.com/v1.0/me/microsoft.graph.sendMail" rel="nofollow noreferrer">https://graph.microsoft.com/v1.0/me/microsoft.graph.sendMail</a>
  SdkVersion : graph-java/v2.3.2 Authorization : [PII_REDACTED]
  {&quot;saveToSentItems&quot;:true,&quot;message&quot;:{&quot;body&quot;:{&quot;conten[...]</p>
  <p>413 : Request Entity Too Large [...]</p>
  </blockquote>
  <p>The above code snippet I've captured from the test case of msgraph-sdk-java repo.</p>
  <p>Please help me to send email with size less then 4 MB.
  Thanks</p>