mongodb nodemailer

Posted cyany_blue

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mongodb nodemailer相关的知识,希望对你有一定的参考价值。

npm i --save nodemailer


var nodemailer = require("nodemailer");


app.get("/sendEmail",function(req,res){
	var mailTrans = nodemailer.createTransport({
		service:\'Gmail\',
		auth:{
			user:\'xxx@gmail.com\',
			pass:xxx
		},
		port:587,
		secure: false,
		tls:{
			rejectUnauthorized:false
		}
	});
	mailTrans.sendMail({
		from:\'xx@163.com\',
		to:\'xxx@163.com\',
		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/


update again .haha

app.get("/sendEmail",function(req,res){
nodemailer.createTestAccount((err, account) => {
    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
            host: "smtp.163.com",
            secureConnection: true,
            port:465,
        auth: {
            user: \'xxx@163.com\', // generated ethereal user
            pass: \'\' // generated ethereal password(授权码)
        }
    });

    // setup email data with unicode symbols
    let mailOptions = {
        from: \'xxx@163.com\', // sender address(注意和上面的要一致)
        to: \'xxx@qq.com\', // list of receivers
        subject: \'Hello ✔\', // Subject line
        text: \'Hello world?\', // plain text body
        html: `<div>
        <h2 style="font-size:30px;color:#53ff53;">haha</h2>
        <a href="http://www.cyany.com">1345648</a>`, // html body
        attachments:[
        	{
        		filename:\'text.txt\',
        		content:\'hello,world\'
        	},
        	{
        		filename:\'text.txt\',
        		path:\'text.txt\'
        	}
        ]
    };

    transporter.verify(function(error, success) {
   if (error) {
        console.log(error);
   } else {
        console.log(\'Server is ready to take our messages\');
   }
});
    // send mail with defined transport object
    transporter.sendMail(mailOptions, (error, info) => {
        if (error) {
            return console.log(error);
        }
        console.log(\'Message sent: %s\', info.messageId);
        // Preview only available when sending through an Ethereal account
        console.log(\'Preview URL: %s\', nodemailer.getTestMessageUrl(info));

        // Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
        // Preview URL: https://ethereal.email/message/WaQKMgKddxQDoou...
    });
});
res.json({code:0})
})

https://nodemailer.com/message/attachments/

以上是关于mongodb nodemailer的主要内容,如果未能解决你的问题,请参考以下文章

如何将代码片段存储在 mongodb 中?

带有 NodeMailer 的 Zoho 不工作错误代码:“EDNS”

工具Node.js邮件发送组件- Nodemailer 1.0发布

找不到模块“nodemailer”

Nodejs 发送邮件 nodemailer

将变量传递给nodemailer中的html模板