Im trying to use OAUTH 2.0 to send emails with Gmail API using Nodemailer
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.
i have followed every detail form (https://nodemailer.com/smtp/oauth2/#examples) But i'm getting following error
{ 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' }
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 (https://myaccount.google.com/lesssecureapps) so there is no error in sending emails using plain username and password but this is not a good approach so OAUTH is the solution
here is my code for you to check (its an express app) running in development running on http://localhost:3000
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
service: 'gmail',
auth: {
type: 'OAuth2',
user: '[email protected]',
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 <[email protected]>',
to: '',
subject: 'Subject ',
text: 'Some thing',
};
transporter.sendMail(mailOptions, (error, response) => {
if(error){
console.log(error); // Always giving Error: connect ETIMEDOUT 74.125.140.108:465
} else {
console.log(response);
}
});
it not even try to login because when login fails it gives error of wrong credentials (checked with plain username and password)
*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