title: gmail send api failed with error code 400 in meteor
body: <p>I am trying to send mail using gmail api in my meteor application, which returning below error,</p>
  
  <pre><code>Error in calendar insert: Error: failed [400] {  "error": {   "errors": [    {        "domain": "global",     "reason": "invalidArgument",     "message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required"    }   ],   "code": 400,   "message": "'raw' RFC822 payload message string or uploading message via /upload/* URL required"  } } 
  </code></pre>
  
  <p>I have tried the below,</p>
  
  <pre><code>"sendGmail": function(str) {
      this.unblock();
          var url = "https://www.googleapis.com/gmail/v1/users/me/messages/send";
  
          var encodedMail = new Buffer(str).toString("base64").replace(/\+/g, '-').replace(/\//g, '_');
  
          try {
          Meteor.http.post(url, {
              'headers' : { 
                  'Authorization': "Bearer " + Meteor.user().services.google.accessToken,
                  'Content-Type': 'application/json' 
              },
              'body': JSON.stringify({
                  "raw": encodedMail
              })
            });
          } catch(e){
              console.log("Error in calendar insert: " + e);
          } finally {
            return true;  
          }
  }
  </code></pre>
  
  <p>passing the below string value as argument:</p>
  
  <pre><code>    var str = "Content-Type: text/plain; charset=\"UTF-8\"\n" +
          "MIME-Version: 1.0\n" +
          "Content-Transfer-Encoding: 7bit\n" +
          "to: arunmail2u@gmail.com\n" +
          "from: arunsugan08@gmail.com\n" +
          "subject: Meteor test mail\n\n" +
  
      "Hi, this is test mail from meteor application";
  
       Meteor.call('sendGmail', str);
  </code></pre>