-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.js
58 lines (49 loc) · 1.48 KB
/
mail.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
const fs = require("fs");
const path = require("path");
const nodemailer = require("nodemailer");
const dotenv = require("dotenv");
const { getPoint } = require("./utils/getPoint");
const { formatInTimeZone } = require("date-fns-tz");
const { generateTodayPointContents } = require("./utils/generateContents");
dotenv.config();
const getMails = () => {
const mailsJSON = fs
.readFileSync(path.resolve(__dirname, "./mails.json"), "utf-8")
.toString();
const { mails } = JSON.parse(mailsJSON);
return [...mails];
};
const sendPointMail = async () => {
const mails = getMails();
const date = formatInTimeZone(new Date(), "Asia/Seoul", "yyyy년 MM월 dd일");
const usaVestData = await getPoint("usa");
const krVestData = await getPoint("south_korea");
const usaInfo = await generateTodayPointContents({
country: "usa",
...usaVestData,
});
const krInfo = await generateTodayPointContents({
country: "south_korea",
...krVestData,
});
const transporter = nodemailer.createTransport({
service: "gmail",
host: "smtp.gmail.com",
port: 587,
secure: false,
auth: {
user: process.env.SEND_EMAIL,
pass: process.env.PASSWORD,
},
});
const info = await transporter.sendMail({
from: process.env.SEND_EMAIL,
to: mails,
subject: `💸 ${date} 바닥 지수 정보 💸 `,
text: `${usaInfo}\n${krInfo}`,
});
console.log("Message sent: %s", info.messageId);
};
sendPointMail().catch((e) => {
console.log(e);
});