index.js
const nodemailer=require("nodemailer") let sendEmail=function () { var transporter = nodemailer.createTransport({ host: "smtp.qq.com", port: 465, secure: true, // use SSL auth: { user: ‘[email protected]‘, pass: ‘密码‘ } }); // setup e-mail data with unicode symbols var mailOptions = { from: ‘"Test ??" <[email protected]>‘, // sender address to: ‘[email protected]‘, // list of receivers subject: ‘Hello ?‘, // Subject line text: ‘Hello world ??‘, // plaintext body html: ‘<b>Hello world ??</b>‘ // html body }; // send mail with defined transport object transporter.sendMail(mailOptions, function(error, info){ if(error){ return console.log(error); } console.log(‘Message sent: ‘ + info.response); }); } module.exports={ sendEmail:sendEmail }
test.js
var send=require("../src/index"); send.sendEmail();
运行
npm src/test
时间: 2024-12-28 00:53:16