mongodb nodemailer

npm i --save nodemailer


var nodemailer = require("nodemailer");


app.get("/sendEmail",function(req,res){
    var mailTrans = nodemailer.createTransport({
        service:'Gmail',
        auth:{
            user:'[email protected]',
            pass:xxx
        },
        port:587,
        secure: false,
        tls:{
            rejectUnauthorized:false
        }
    });
    mailTrans.sendMail({
        from:'[email protected]',
        to:'[email protected]',
        subject:'my subject is here',
        text:'thank your for your letter !'
    },function(err){
        if(err) console.log('unabled to send email'+err);
    });
    res.json({code:0})
})

question:

Reference:
https://stackoverflow.com/questions/31473292/etimedout-connect-error-using-nodemailer-in-nodejs-openshift-application
http://masashi-k.blogspot.com/2013/06/sending-mail-with-gmail-using-xoauth2.html
https://nodemailer.com/about/

猜你喜欢

转载自www.cnblogs.com/cyany/p/9973791.html