I'd like to send mail via the Graph API and attach a file by its drive item ID.
At the moment I can successfully send email via the Graph API and attach a file that is on my local server.
However the file originates on OneDrive so the current situation is I have to download the file to my server then re-upload it via the sendMail endpoint as an attachment and then delete it from my server.
This seems like an unneeded step if it's possible to just provide the file ID and let office 365 resolve it all locally.
$mailBody = ...
'attachments' => [
[
'@odata.type' => '#microsoft.graph.fileAttachment',
'Name' => 'file.docx',
'ContentBytes' => $localFile
// 'DriveID' => 'possibly this instead of Content Bytes?'
]
]
...
$response = $this->getGraph()->createRequest("POST", "/users/{primary-user}/sendMail")
->attachBody($mailBody)
->execute();