title: Gmail API for sending mails in Node.js
body: <h3>Disclaimer:</h3>
  
  <ul>
  <li>I have followed Google's own <a href="https://developers.google.com/gmail/api/quickstart/nodejs" rel="noreferrer">Node.js quickstart guide</a> and successfully connect and use the  <code>gmail.users.labels.list()</code> functionality.</li>
  <li>I have checked for questions/answers here, like <a href="https://stackoverflow.com/a/29515412/2256325">this one</a> (that is not using the Node.js API I am asking about), or <a href="https://stackoverflow.com/a/25597617/2256325">this one</a> (similar to <a href="https://stackoverflow.com/a/30613517/2256325">this one</a>) which apparently is the same problem I have but the solution does not work.</li>
  </ul>
  
  <h3>My problem:</h3>
  
  <p>When using <a href="https://github.com/google/google-api-nodejs-client" rel="noreferrer">Google's Node.js API</a> I get a error trying to send a email. The error is:</p>
  
  <pre><code>{
      "code": 403,
      "errors": [{
          "domain": "global",
          "reason": "insufficientPermissions",
          "message": "Insufficient Permission"
      }]
  }
  </code></pre>
  
  <h3>My setup:</h3>
  
  <pre><code>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)
      });
  }
  </code></pre>
  
  <p>The function <code>processClientSecrets</code> is from the Google guide i mentioned above. It reads my <code>.json</code> file that has my <code>access_token</code> and <code>refresh_token</code>. The <a href="https://gist.github.com/SergioCrisostomo/60de7a702ea839a64b32" rel="noreferrer"><code>makeBody</code> function</a> is a to make a encoded body message.</p>
  
  <p>In the config variabels I have also:</p>
  
  <pre><code>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'
  ];
  </code></pre>
  
  <h3>Why it should work:</h3>
  
  <ul>
  <li>the authorization process works for the <code>gmail.users.labels.list()</code> method.</li>
  <li>the message body I'm testing works if I test it at <a href="https://developers.google.com/gmail/api/v1/reference/users/messages/send" rel="noreferrer">Google's test page</a>.</li>
  </ul>
  
  <hr>
  
  <h3>My question:</h3>
  
  <p>Is my setup wrong? Have there been changes in the API? What am I missing?</p>