安装
npm install nodemailer
示例
'
use strict'; // 引入依赖 const nodemailer = require('nodemailer'); /** * 发送163邮件 */ async function sendEmail() { // 配置邮件服务器 let transporter = nodemailer.createTransport({ host: "smtp.163.com", port: 25, secure: false, auth: { user: '用户名', pass: '密码或授权码', }, }); // 发送邮件 let info = await transporter.sendMail({ from: '"邮件显示名" <from@163.com>', to: "to@163.com", subject: "邮件标题", text: '文本邮件内容', html: "<b>HTML邮件内容</b>", }); } sendEmail();