nodejs-邮件定时发送
作者:互联网
const nodemailer = require('nodemailer');
const { default: Axios } = require('axios');
const schedule = require("node-schedule");
async function sendMail(text) {
var user = "1178980144@qq.com";//自己的邮箱
var pass = "szcvaoodhrknjhfd"; //qq邮箱授权码,如何获取授权码下面有讲
var to = "1105182298@qq.com";//对方的邮箱
let transporter = nodemailer.createTransport({
host: "smtp.qq.com",
port: 587,
secure: false,
auth: {
user: user, // 用户账号
pass: pass, //授权码,通过QQ获取
},
});
let info = await transporter.sendMail({
from: `亲爱的老公<${user}>`, // sender address
to: `亲爱的老婆<${to}>`, // list of receivers
subject: "亲爱的老婆", // Subject line
text: text, // plain text body
});
console.log("发送成功");
}
function getHoneyedWords() {
const url = "https://chp.shadiao.app/api.php";
// 获取这个接口的信息
return Axios.get(url);
}
//每天下午5点21分发送
schedule.scheduleJob({ hour: 17, minute: 20 }, function () {
console.log("启动任务:" + new Date());
getHoneyedWords().then((res) => {
console.log(res.data);
sendMail(res.data);
});
});
标签:qq,const,nodejs,text,sendMail,pass,console,定时,邮件 来源: https://blog.csdn.net/qq_34870529/article/details/112437878