According to the Send attachments with your Gmail documentation:
You can send up to 25 MB in attachments. If you have more than one attachment, they can't add up to more than 25 MB.
If your file is greater than 25 MB, Gmail automatically adds a Google Drive link in the email instead of including it as an attachment.
But the last sentence refers to the Gmail UI, and not if you are using the API.
So essentially you cannot upload directly the attachment to the Gmail - you will have to upload it to Google Drive first and afterwards send it in the e-mail.
A possible solution:
- Upload the file which you want to send to Google Drive by using the Google Drive API v3. Since you want to upload a file bigger than 25 mb you should use the resumable upload. The resumable upload is a more reliable type of transfer and especially important with large files.
var options = {
url: 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
},
//other options
}
- Retrieve the file from Drive by using the Drive API and set the permissions necessary to be able to share the file. Afterwards you have to use the NPM module
async
to synchronize the changes in the permissions.
var fileId = 'ID_OF_THE_FILE';
var permissions = [
{
'type': 'user',
'role': 'writer',
'emailAddress': 'user@example.com'
}, {
'type': 'domain',
'role': 'writer',
'domain': 'example.com'
}
];
- Send the e-mail with the link for the file wanted in the body.
Note: you also have to authorize the necessary scopes both for Drive and Gmail.
Moreover, I suggest you check the following links since they might be of help: