模块
nodemailer
npm install nodemailer --save
实例
'use strict';
const nodemailer = require('nodemailer');
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp-mail.outlook.com',
port: 587,
secure: false, // secure:true for port 465, secure:false for port 587
auth: {
user: 'boxuerixin@hotmail.com',
pass: 'xxx'
}
});
// 个人邮箱,总是被当作垃圾处理。。。
// let transporter = nodemailer.createTransport({
// host: 'smtp.mxhichina.com',
// port: 465,
// secure: true, // secure:true for port 465, secure:false for port 587
// auth: {
// user: 'zhangdanyang@zhangdanyang.com',
// pass: 'xxx'
// }
// });
// setup email data with unicode symbols
let mailOptions = {
from: '"张丹阳" <boxuerixin@hotmail.com>', // sender address
to: 'boxuerixin@qq.com', // list of receivers
subject: '来自zhangdanyang.com的邮件', // Subject line
text: '貌似没啥用', // plain text body
html: '<b>正文</b>' // html body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
console.log("send")
if (error) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。