title: nodemailer and gmail APIs
body: <p>Im trying to get nodemailer working using Google GMail API.
  I've got my Google project set up - using their oauth sandbox for redirect,
  I've got a clientID, secret and refresh token from my developers console.</p>
  
  <p>The Code</p>
  
  <pre><code>const nodemailer = require('nodemailer');
  const xoauth2 = require('xoauth2');
  
  // create reusable transporter
  let transporter = nodemailer.createTransport( {
          service: 'gmail',
          xoauth2: xoauth2.createXOAuth2Generator({
              user: 'me@myDomain.com',
              clientid: 'blahblahblah.apps.googleusercontent.com',
              clientSecret: 'k33p-gUeSsINg',
              refreshToken: '123BritneyIsTheBest'
          }),
          tls: {
              rejectUnauthorized: false
          }
      } );
  
  // setup email data
  let mailOptions = {
      from: 'me@myDomain.com',
      to: 'me@yahoo.com',
      subject: 'Hello there Google API...',
      text: 'Hello Google API',
      html: '&lt;b&gt;Hello Google API&lt;/b&gt;'
  };
  
  // send mail with defined transport object
  transporter.sendMail(mailOptions, (error, info) =&gt; {
      if (error) {
          return console.log(error);
      }
      console.log('Message sent: ', info.messageId);
  });
  </code></pre>
  
  <p>The Error.</p>
  
  <pre><code>{ 
      Error: Mail command failed: 530-5.5.1 Authentication Required. Learn more at 530 5.5.1  https://support.google.com/mail/?p=WantAuthError l24sm4075119ywk.21 - gsmtp
      at SMTPConnection._formatError (C:\abc\index.js:591:19)
      at SMTPConnection._actionMAIL (C:\abc\index.js:1350:34)
      at SMTPConnection._responseActions.push.str (C:\abc\index.js:840:18)
      at SMTPConnection._processResponse (C:\abc\index.js:747:20)
      at SMTPConnection._onData (C:\abc\index.js:543:14)
      at TLSSocket._socket.on.chunk (C:\abc\index.js:495:47)
      at emitOne (events.js:116:13)
      at TLSSocket.emit (events.js:211:7)
      at addChunk (_stream_readable.js:263:12)
      at readableAddChunk (_stream_readable.js:250:11)
      code: 'EENVELOPE',
      response: '530-5.5.1 Authentication Required. Learn more at\n530 5.5.1  https://support.google.com/mail/?p=WantAuthError l24sm4075119ywk.21 - gsmtp',
      responseCode: 530,
      command: 'MAIL FROM' 
  }
  </code></pre>
  
  <p>I have tried this - and it works, but it's my understanding that this is very unsecured and NOT acceptable for production.</p>
  
  <pre><code>const nodemailer = require('nodemailer');
  
  // create reusable transporter object
  let transporter = nodemailer.createTransport( {
      host: 'smtp.gmail.com',
      port: 587,
      secure: false,
      auth: {
          user: 'me@myDomain.com',
          pass: 'Seriously?'
      }
  });
  
  ... all the rest is the same, removed for brevity...
  </code></pre>
  
  <p>The existing posts solutions have not helped.
  Thank You</p>