Disclaimer:
- I have followed Google's own Node.js quickstart guide and successfully connect and use the
gmail.users.labels.list()
functionality. - I have checked for questions/answers here, like this one (that is not using the Node.js API I am asking about), or this one (similar to this one) which apparently is the same problem I have but the solution does not work.
My problem:
When using Google's Node.js API I get a error trying to send a email. The error is:
{
"code": 403,
"errors": [{
"domain": "global",
"reason": "insufficientPermissions",
"message": "Insufficient Permission"
}]
}
My setup:
fs.readFile(secretlocation, function processClientSecrets(err, content) {
if (err) {
console.log('Error loading client secret file: ' + err);
return;
}
authorize(JSON.parse(content), sendMessage);
});
function sendMessage(auth) {
var raw = makeBody('myrealmail@gmail.com', 'myrealmail@gmail.com', 'subject', 'message test');
gmail.users.messages.send({
auth: auth,
userId: 'me',
message: {
raw: raw
}
}, function(err, response) {
res.send(err || response)
});
}
The function processClientSecrets
is from the Google guide i mentioned above. It reads my .json
file that has my access_token
and refresh_token
. The makeBody
function is a to make a encoded body message.
In the config variabels I have also:
var SCOPES = [
'https://mail.google.com/',
'https://www.googleapis.com/auth/gmail.modify',
'https://www.googleapis.com/auth/gmail.compose',
'https://www.googleapis.com/auth/gmail.send'
];
Why it should work:
- the authorization process works for the
gmail.users.labels.list()
method. - the message body I'm testing works if I test it at Google's test page.
My question:
Is my setup wrong? Have there been changes in the API? What am I missing?