-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (30 loc) · 955 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
require("env2")("./.env"); // 环境变量
const nodemailer = require("nodemailer"); //发送邮件的node插件
const { EmailToArr, EmianService, EamilAuth } = require("./config");
const getAllData = require("./superagent");
const getHtmlData = require("./view");
const sendMail = require("./email");
const scheduleRun = require("./schedule");
let transporter = nodemailer.createTransport({
service: EmianService,
port: 465,
secureConnection: true,
auth: EamilAuth,
pool: true
});
const getAllDataAndSendMail = async () => {
for (let i = 0, len = EmailToArr.length; i < len; i++) {
try {
let item = EmailToArr[i];
let apiData = await getAllData(item.CITY, item.LOCATION);
let htmlData = await getHtmlData(apiData);
await sendMail(transporter, item.TO, htmlData);
} catch (error) {
console.error(error);
}
}
};
// test
// getAllDataAndSendMail()
// 定时
scheduleRun(getAllDataAndSendMail);