-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathindex.js
43 lines (37 loc) · 1.06 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
const nodemailer = require("nodemailer");
const { randomFetch, buildEmailContent } = require("./notion.js");
require("dotenv").config();
const userEmail = process.env.SENDING_EMAIL;
const password = process.env.SENDING_PASSWORD;
const destinationEmail = process.env.DESTINATION_EMAIL;
if (!userEmail || !password || !destinationEmail) {
console.error(
"You must provide sending email, password and the destination email"
);
process.exit(1);
}
const main = async function () {
let mailTransporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: userEmail,
pass: password,
},
});
const resp = await randomFetch();
const emailContent = buildEmailContent(resp);
let mailDetails = {
from: userEmail,
to: destinationEmail,
subject: "[NMS] Scheduled vocabulary review",
html: emailContent,
};
mailTransporter.sendMail(mailDetails, function (err, data) {
if (err) {
console.error("Can't send email: ", err.message);
} else {
console.log("Email sent successfully");
}
});
};
main();