Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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 <[email protected]>\r\n' +
        'To: Me <[email protected]>\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.

like image 947
user555 Avatar asked Dec 12 '25 16:12

user555


1 Answers

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.

like image 184
Tholle Avatar answered Dec 15 '25 09:12

Tholle



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!