简体   繁体   中英

sending email with nodemailer version 2.0

I want to send email from localhost with nodemailer. Function to send email is below

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

}

if I call the function, it is return undefined . I don't have any idea whic part is missing or error How do I fix it?

Sorry I do not have enough reputation to make comment hence answering. Could you please console the error and the info to see what google smtp is responding with.

Finally, my function is working. I was showing the error in console and it is

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

I am uninstalling avast (antivirus) in my windows. Then, I can send email from localhost using nodemailer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM