使用nodemailer 2.0版发送电子邮件

时间:2016-02-01 06:27:49

标签: node.js smtp nodemailer

我想通过nodemailer从localhost发送电子邮件。发送电子邮件的功能如下

sendEmail : function(toEmail, subjek, param){
var transporter = nodemailer.createTransport(smtpTransport({
        host : "smtp.gmail.com",
        port : 465,
        secure : true, 
        ignoreTLS : true,
        auth : {
            username : config.userMail,
            password : config.passMail
        }
    template = fs.readFileSync('public/views/emailTemplate/token.hjs','utf-8'),
    compiledTemplate = Hogan.compile(template);

// setup e-mail data with unicode symbols
var mailOptions = {
    from: 'User', // sender address
    to: toEmail, // list of receivers
    subject: subjek, // Subject line
    html: compiledTemplate.render(param)
};

// send mail with defined transport object
transporter.sendMail(mailOptions, function(error, info){

     if(error){
         return error
     }else{
         return info         
     }
});

}

如果我调用该函数,则返回undefined。我不知道哪个部分丢失或错误 我该如何解决?

2 个答案:

答案 0 :(得分:0)

抱歉,我没有足够的声誉发表评论,因此回答。你能否安慰一下错误和信息,看看google smtp正在回复什么。

答案 1 :(得分:0)

最后,我的功能正在发挥作用。 我在控制台中显示错误,它是

 {[Error Self signet certificate in certificate chain ] Code : 'SEL_SIGNED_CERT_CHAIN']; 

我正在Windows中卸载avast(防病毒)。然后,我可以使用nodemailer从localhost发送电子邮件。