本文介绍了使用 Nodemailer 提交电子邮件时出现 NodeJs 错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我已按照以下步骤设置 nodemailer1) 允许访问 Gmail 中安全性较低的应用2)在app.js中写如下

I have followed these steps to setup nodemailer1) Allow access to less secure apps in gmail2) 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) 一旦我点击提交电子邮件,我就会收到以下错误

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/tfsqu6ir90s68​​2h/ErrorOnceSubmissionDone.wmv?dl=0

提前致谢

纳文

推荐答案

使用下面的代码从 nodemailer 发送电子邮件,在函数内部传递你的参数,你会得到你的结果.

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);
});

}

这篇关于使用 Nodemailer 提交电子邮件时出现 NodeJs 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 03:07