npm install nodemailer --save
const nodemailer = require("nodemailer");
"use strict";
const nodemailer = require("nodemailer");
const MailSettings = require("../config/MailSettings");
// async..await is not allowed in global scope, must use a wrapper
async function sendMailTo(mailUserName, mailContent){
// Generate test SMTP service account from ethereal.email
// Only needed if you don't have a real mail account for testing
let account = await MailSettings.createSenderAccount();
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: "smtp.qiye.163.com",
port: 994,
secure: true, // true for 465, false for other ports
auth: {
user: account.user, // generated ethereal user
pass: account.pass // generated ethereal password
},
});
// setup email data with unicode symbols
let mailOptions = {
from: '中寰App通知公共邮箱 <app_notice@aerozhonghuan.com>', // sender address
to: `${mailUserName}@aerozhonghuan.com`, // list of receivers
subject: mailContent.subject, // Subject line
// text: mailContent.text, // plain text body
html: mailContent.html // html body
};
// send mail with defined transport object
let info = await transporter.sendMail(mailOptions);
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...
}
/* 使用 DEMO
let mail = {
subject: "验证码", // Subject line
html: "你的验证码是 <B>123</B>", // plain text body
}
sendMail('zhangyunfei',mail).catch(console.error);
*/
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有