NodeJs Error When Submitting Email using Nodemailer

Viewed 6791

I have followed these steps to setup nodemailer 1) Allow access to less secure apps in gmail 2) Written the following in app.js

app.post('/reachus/send',function(req,res){
var transporter=nodemailer.createTransport({
    service:'Gmail',
    auth: {
        user:'my@gmail.com',
        pass:'***'
    }
});

var mailOptions={
    from:'Naveen DK <my@gmail.com>',
    to:'my@gmail.com',
    subject:'Email Sent from your website',
    text:'You have a submission with the following details.. Name: '+req.body.name +'Email: '+req.body.email+' Message: '+ req.body.message,
    html:   '<p>You have a submission with the following details..</p><ul><li> Name :'+req.body.name + ' </li><li>Email: '+req.body.email +'</li><li>Message ' + req.body.message +'</li></ul>'
};

transporter.sendMail(mailOptions,function(error,info){
    if(error){
        console.log(error);
        res.redirect('/');
    } else{
        console.log('Message Sent ' + info.response);
        res.redirect('/');
    }
  });
});

3) Once I Click on Submit Email I get the following error

 { Error: read ECONNRESET
    at exports._errnoException (util.js:1026:11)
    at TLSWrap.onread (net.js:569:26)
    code: 'ECONNECTION',
    errno: 'ECONNRESET',
    syscall: 'read',
    command: 'CONN
 }

Please find the below 2 vids for more details

1 https://www.dropbox.com/s/nc1zvivlfpabj6h/HowMyCodeLooksLike.wmv?dl=0

2 https://www.dropbox.com/s/tfsqu6ir90s682h/ErrorOnceSubmissionDone.wmv?dl=0

Thanks in advance

Naveen

2 Answers
Related