I'm trying to send email using gmail-api, I'm reading data from user and
converted it to base64url string
I'm getting the raw value and when I try to send the mail using post request
var ss=new Buffer(message).toString('base64')
var rawdata = ss.replace(/\//g, '_').replace(/\+/g, '-');
var options={"access_token":google.accessToken,'raw':rawdata};
var res=HTTP.post('https://www.googleapis.com/gmail/v1/users/me/messages/send',{params: options});
It is throwing error
{ "error": { "errors": [
{ "domain": "global",
"reason": "parseError",
"message": "This API does not support parsing form-encoded input." } ],
"code": 400, "message": "This API does not support parsing form-encoded input." } }
I'm sending following params
var message = 'From: Me <ff@gmail.com>\r\n' +
'To: Me <ss@gmail.com>\r\n' +
'Subject: Hello\r\n'+
'Mime-Version: 1.0\r\n'+
'Content-Type: text/html; charset=utf-8\r\n' +
'Content-Transfer-Encoding: quoted-printable\r\n\r\n' +
'<html><body>' +
'<h1>World</h1>' +
'</body></html>';
I'm using valid emails in my app,
Important thing is when I paste the generated raw in gmail-api explorer,
It is working fine and the email is sending, but when I send post request with the same raw it is throwing error.
EDIT: accesstokens are also fine, they are working for other queries.
What is the error in my code?I suppose the error is with headers.
Any help appreciated.
I would suspect that when you don't specify a 'Content-Type'-header, it defaults to "application/x-www-form-urlencoded". Try specifying the Content Type yourself to "application/json".