Reputation: 11
I am trying to send an email which has attachments in it, using Gmail APIs, I am using NodeJS, I have read this document
https://developers.google.com/gmail/api/guides/uploads#multipart
But I am not sure what I am missing in headers, the following is the code
I have to send an email which has an attachment which is more than 25 MB so for that, I am using multipart of Gmail, following is the code
const options = {
uri: 'https://www.googleapis.com/upload/gmail/v1/users/[email protected]/messages/send?uploadType=multipart',
method: apiConfig.method,
media: {mimeType: 'message/rfc822', body: requestParameter.dataObj.raw},
headers: {
Authorization: 'Bearer ' + token,
'Content-type': 'message/rfc822'
},
json: true
}
Upvotes: 0
Views: 602
Reputation: 6072
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:
var options = {
url: 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable',
headers: {
'Authorization': 'Bearer ' + token,
'Content-Type': 'application/json',
},
//other options
}
async
to synchronize the changes in the permissions.var fileId = 'ID_OF_THE_FILE';
var permissions = [
{
'type': 'user',
'role': 'writer',
'emailAddress': '[email protected]'
}, {
'type': 'domain',
'role': 'writer',
'domain': 'example.com'
}
];
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:
Upvotes: 1