3

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:'[email protected]',
        pass:'***'
    }
});

var mailOptions={
    from:'Naveen DK <[email protected]>',
    to:'[email protected]',
    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

3
  • you have not pass "host" in createTrasport Commented Aug 16, 2017 at 7:37
  • I have tried the following: Method one -passing the host ---------------- app.post('/reachus/send',function(req,res){ var transporter=nodemailer.createTransport({ pool:true, host:'smtp.gmail.com', port:465, secure:true, auth: { user:'', pass:'' } }); ---------------- Tried by adding nodemailer-smtp-transport' ---------- app.post('/reachus/send',function(req,res){ var transporter = nodemailer.createTransport(smtpTransport({ service:'gmail', auth: { user:'', pass:'' } })); ----But no luck Commented Aug 16, 2017 at 8:53
  • it resolved your problem?? Commented Aug 16, 2017 at 8:58

2 Answers 2

3

use below code for sending email from nodemailer, inside function pass ur parameter and you will get ur result.

var AppConfig = {
'sendEmailID': 'useremail',
'sendEmailFromName': 'senderemail',
'sendEmailPassword': 'password'

}

function SendEmail(toEmail, Subject, html) {
// create reusable transporter object using the default SMTP transport 
var transporter = nodemailer.createTransport({
    host: 'smtp.gmail.com',
    port: '587',
    auth: {
        user: "username",
        pass: AppConfig.sendEmailPassword
    },
    secureConnection: 'false',
    tls: {
        ciphers: 'SSLv3'
    }

});

// setup e-mail data with unicode symbols 
var mailOptions = {
    from: AppConfig.sendEmailFromName, // sender address 
    to: toEmail, // list of receivers 
    subject: Subject, // Subject line 
    html: html // html body 
};

// send mail with defined transport object 
transporter.sendMail(mailOptions, function (error, info) {
    if (error) {
        return console.log("ERROR----" + error);
    }
    console.log('Message sent: ' + info.response);
});

}

Sign up to request clarification or add additional context in comments.

Comments

2

With the response I got from @chetan mekha I changed my code as follows:

var  smtpTransport=nodemailer.createTransport({
   host: 'smtp.gmail.com',
    port: '587',
    auth: {
        user: "**",
        pass: "**"
    },
    secureConnection: 'false',
    tls: {
        ciphers: 'SSLv3'

    }
});

But there another error came up saying : { [Error: self signed certificate in certificate chain] code: 'ECONNECTION', command: 'CONN' } But adding the line rejectUnauthorized: false under ciphers made it work! so final code snippet that worked for me looks like this..

var  smtpTransport=nodemailer.createTransport({
   host: 'smtp.gmail.com',
    port: '587',
    auth: {
        user: "**",
        pass: "**"
    },
    secureConnection: 'false',
    tls: {
        ciphers: 'SSLv3',
        rejectUnauthorized: false

    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.