Skip to content Skip to sidebar Skip to footer

Send Mail With Attachment Microsoft Graph Not Working

I am making an application that sends emails from a User as described by this article. Everything is working as expected, except for when I try to include an attachment. The email

Solution 1:

Attachments go inside the message JSON, not outside of it. This should work:

function sendMailRequest(access_token, message, uriSend, file, base64, callback) {
  const attachments = [
    {
      "@odata.type": "#microsoft.graph.fileAttachment",
      "contentBytes": base64
      "name": "example.jpg"
    }
  ];

  message["attachments"] = attachments;

  // Configure the request
  var options2 = {
    "url": uriSend,
    "method": "POST",
    "headers": { 
      "Authorization": access_token,
      "Content-Type": "application/json"
    },
    "body": JSON.stringify({
      "message": message, 
      "SaveToSentItems": "true"
    })
  }
  ...
}

Post a Comment for "Send Mail With Attachment Microsoft Graph Not Working"