0
votes

I want to send email via Gmail or other email provider like office 365 using Nodemailer as my module Node.js.

I wanna ask also if there's a proxy or firewall setting to disable so that I can send email using gmail or office 365.

Or maybe there is something wrong with my code ?

const nodemailer = require("nodemailer");

const smtpTransport = require('nodemailer-smtp-transport');

function sendEmail(to, subject, html){

nodemailer.createTestAccount((err, account) => {
  let transporter = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: 465,
    secure: true,
    auth: {
      user: '[email protected]',
      pass: 'sercretpass'
    }
});

let mailOptions = { from: '"Admin" ', to: to, subject: subject, html: html };

    transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            console.log('Error', error);
        }
        else{
            console.log('Success', info);
        }
    });
});

}

module.exports.sendEmail = sendEmail;

MY ERROR :

Error { Error: connect ETIMEDOUT 74.125.203.108:465 at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1121:14) errno: 'ETIMEDOUT', code: 'ECONNECTION', syscall: 'connect', address: '74.125.203.108', port: 465, command: 'CONN' }

1

1 Answers

0
votes

Are you able to telnet to smtp.gmail.com from the machine on port 465 ? Also try with Port 587, with 587, you should see some other error as it works on STARTTLS.