44 lines
1.1 KiB
JavaScript
44 lines
1.1 KiB
JavaScript
const nodemailer = require('nodemailer');
|
||
const fs = require('fs');
|
||
const path = require('path');
|
||
|
||
// https://segmentfault.com/a/1190000012251328
|
||
// 163 邮箱授权码 lb714500
|
||
// qq 邮箱授权码 ogmqticmpbnoeaje
|
||
|
||
let transporter = nodemailer.createTransport({
|
||
// 服务器地址
|
||
host: 'smtp.163.com',
|
||
// 使用了内置传输发送邮件 查看支持列表:https://nodemailer.com/smtp/well-known/
|
||
service: '163',
|
||
// SMTP 端口
|
||
port: 465,
|
||
// 使用SSL
|
||
secureConnection: true,
|
||
auth: {
|
||
user: 'lb2271608011@163.com',
|
||
// 这里密码不是qq密码,是smtp授权码
|
||
pass: 'lb714500',
|
||
}
|
||
|
||
});
|
||
|
||
let mailOptions = {
|
||
// "发件人名称" <发件人邮箱>
|
||
from: '"163邮箱给qq发邮件" <lb2271608011@163.com>',
|
||
// 接收人邮箱
|
||
to: '2271608011@qq.com',
|
||
// 邮件标题
|
||
subject: 'Hello',
|
||
// 发送text或者html格式
|
||
// text: 'Hello world?',
|
||
html: fs.createReadStream(path.resolve(__dirname, 'mail.html')) // html body
|
||
};
|
||
|
||
transporter.sendMail(mailOptions, (error, info) => {
|
||
if (error) {
|
||
return console.log(error);
|
||
}
|
||
console.log(info);
|
||
|
||
}); |