Biplab Malakar
Biplab Malakar

Reputation: 788

Cannot send email in nodejs using nodemailer

I used nodemailer and my code as follows:

const nodemailer = require('nodemailer');  
module.exports = function(obj) {
    return new Promise((resolve, reject) => {
        console.log('In root to mail send file...');
        let transporter = nodemailer.createTransport({
            service: 'gmail',
            auth: {
                user: '[email protected]',
                pass: 'my password'
            }
        });
        let mailOptions = {
            from: '<[email protected]>', // sender address
            to: obj.email, // list of receivers
            subject: obj.subject, // Subject line
            text: obj.msg, // plain text body
            html: obj.html_msg // html body
        };
        console.log('sending function');
        transporter.sendMail(mailOptions, (error, info) => {
            if (error) {
                console.log('Error due to send mail' + error);
                reject(error);
            } else {
                console.log('Message %s sent: %s', info.messageId, info.response);
                resolve(info);
            }
        });
    });
}

When I run the code, I got this error

{ 
  Error: connect ETIMEDOUT 74.125.200.109:465    at
  Object.exports._errnoException (util.js:1022:11)     at
  exports._exceptionWithHostPort (util.js:1045:20 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1090:14)   
 code: 'ECONNECTION',
 errno: 'ETIMEDOUT',
 syscall: 'connect',
 address: '74.125.200.109',
 port: 465,
 command: 'CONN' 
}

I don't know why, please help me if anybody know why this error occurred.

I have already set Access for less secure apps: turn on in my gmail account.

Upvotes: 1

Views: 798

Answers (1)

Rahul Kumar
Rahul Kumar

Reputation: 5229

You could be behind a network proxy which could be causing a timeout error.

Upvotes: 1

Related Questions