title: Nodemailer OAUTH Gmail connection (Error: connect ETIMEDOUT 74.125.140.108:465)
body: <p>Im trying to use OAUTH 2.0 to send emails with Gmail API using Nodemailer </p>
  
  <p>I have Enable the Gmail API and i have clientId, clientSecret, refreshToken and accessToken (refreshtoken and accesstoken were taken from developers.google.com/oauthplayground) because these all were needed for OAUTH to work.</p>
  
  <p>i have followed every detail form (<a href="https://nodemailer.com/smtp/oauth2/#examples" rel="nofollow noreferrer">https://nodemailer.com/smtp/oauth2/#examples</a>)
  But i'm getting following error</p>
  
  <pre><code>{ Error: connect ETIMEDOUT 74.125.140.108:465
      at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1097:14)
    errno: 'ETIMEDOUT',
    code: 'ESOCKET',
    syscall: 'connect',
    address: '74.125.140.108',
    port: 465,
    command: 'CONN' }
  </code></pre>
  
  <p><strong>But there is a catch when i use Plain username and password there is no connection timeout error because i have already enabled less secure app access form (<a href="https://myaccount.google.com/lesssecureapps" rel="nofollow noreferrer">https://myaccount.google.com/lesssecureapps</a>) so there is no error in sending emails using plain username and password</strong> but this is not a good approach so OAUTH is the solution</p>
  
  <p>here is my code for you to check (its an express app) running in development running on <a href="http://localhost:3000" rel="nofollow noreferrer">http://localhost:3000</a>  </p>
  
  <pre><code>var nodemailer = require('nodemailer');
  var transporter = nodemailer.createTransport({
  host: 'smtp.gmail.com',
  port: 465,
  secure: true,
  service: 'gmail',
  auth: {
    type: 'OAuth2',
    user: 'mygmailaddress@gmail.com',
    clientId: 'clientID',
    clientSecret: 'clientSecret',
    refreshToken: 'refresh token obtained from https://developers.google.com/oauthplayground',
    accessToken: 'access token also obtained from https://developers.google.com/oauthplayground'
  }
  });
  var mailOptions = {
      from: 'me &lt;myemailaddress@gmail.com&gt;',
      to: '',
      subject: 'Subject ',
      text: 'Some thing',
    };
  
    transporter.sendMail(mailOptions, (error, response) =&gt; {
      if(error){
          console.log(error);   // Always giving Error: connect ETIMEDOUT 74.125.140.108:465
      } else {
          console.log(response);
      }
  });
  </code></pre>
  
  <p>it not even try to login because when login fails it gives error of wrong credentials (checked with plain username and password)</p>
  
  <p>*Note please don't mark this question as duplicate because i have check almost all other question and answers but nothing worked 
  some people said its because of firewall setting i have check that too but didn't worked 
  So whats the issue and how to solve it</p>