user555 user555 - 1 year ago 385
Node.js Question

send email using gmail api Error: This API does not support parsing form-encoded input

I'm trying to send email using gmail-api, I'm reading data from user and
converted it to


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'',{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 <>\r\n' +
'To: Me <>\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>' +

I'm using valid emails in my app,

Important thing is when I paste the generated
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.

Answer Source

I would suspect that when you don't specify a Content-Type-header, it defaults to application/x-www-form-urlencoded. Try setting the Content-Type yourself to application/json.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download