Sending a message with a large attachment used to be the least worst option when it came to shipping data between people. In the Modern workplace where document and file sharing options are a lot better sending email with a large attachment can tends now to be the worst option especially when it comes to version control, expiration etc. However if you do find yourself with the need to send an email with large attachments (larger then 4MB) and you want to make use of the Microsft Graph API then it requires you use a different method from just sending the message in one post eg https://docs.microsoft.com/en-us/graph/outlook-large-attachments?tabs=http
This does make sending a Message a lot more complex eg if you have a Message less the 4MB you can just make one REST Post to send that message. If you have a large attachment you then have a multi step process eg
- Create a Draft message where you set all the other message property eg Subject,To,Body
- Take the MessageId(graph item id) returned in Step 1 and Create an Upload Session
- Read the attachment and upload the attachment in chunks until you have uploaded the entire file
- Send the Draft Message
I've put together a Powershell sample and posted it on GitHub https://github.com/gscales/Powershell-Scripts/blob/master/Graph101/SendMessageWithLargeAttachment.ps1 that performs the above to run this use something like
Invoke-SendMessageWithLargeAttachment -MailboxName gscales@....com -filePath "C:\temp\rates.pdf" -verbose -uploadChunkSize 400000 -Subject "Test Message 1234" -body "Rgds Glen" -To glenscales@yahoo.com
The chunk size you use is up to you a larger chunk size will generally mean a faster upload but if the Network is more unreliable a smaller chunk is better