const nodemailer = require(“nodemailer”);
let adminConfig = {
host: ‘xxx.163.com’, // 邮箱主机地址
// port: 465, // SMTP 端口 SSL的同465
// secure: true,
ignoreTLS: true,
auth: {
user: ‘xxx.com’, // 邮箱账号
pass: ‘xxx’, //密码
}
}
const sendEmail = async (userEmail, name, code) => {
let transporter = nodemailer.createTransport(adminConfig);
let mailOptions = {
from: ‘管理员<xxx.com>’,
to: userEmail,
subject: 你好!${name}
, // 邮件主题
html: 可以使用html:<h1 style='font-size:30px'>${code}</h1>
// 发送内容
};
await transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
console.log(给${name}发了一封邮件,得得
);
});
return null
}
module.exports = sendEmail