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: 'xxx@qq.com',
pass: '密码'
}
});
// setup e-mail data with unicode symbols
var mailOptions = {
from: '"Test ?" <xxxxxx@qq.com>', // sender address
to: 'xxxxxxx@qq.com', // 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