-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
82 lines (73 loc) · 1.92 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";
require("dotenv").config();
const nodemailer = require("nodemailer");
const showdown = require("showdown");
const fs = require("fs");
const emails = require("./emails");
var EmailList = undefined;
var htm = undefined;
const HtmlToMark = (content) => {
const converter = new showdown.Converter();
const text = content;
let html = converter.makeHtml(text);
// console.log(html);
return html;
};
const SendLastFile = async () => {
fs.readdir("./content", (err, files) => {
if (err) {
console.error(err);
s(undefined);
}
fs.readFile(`./content/${files[files.length - 1]}`, "utf8", (err, data) => {
if (err) {
console.error(err);
s(undefined);
}
// console.log(data);
let html = HtmlToMark(data);
// DATAREADY = true;
// console.log(html)
s(html);
});
});
// FileName = GetLastFile();
// console.log("sai"+FileName);
// function func(d){
// htm = d
// console.log("s"+htm)
// }
// return htm
//
};
const transporter = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
auth: {
type: "login", // default
user: process.env.EMAIL,
pass: process.env.PASS,
},
});
async function main(data) {
console.log("Sending Mail...");
EmailList = await emails.getData()
// console.log(EmailList)
EmailList.forEach(async (val) => {
const info = await transporter.sendMail({
from: "Saigenix", // sender address
to: val.email, // list of receivers
subject: `Hello ${val.name}! 👋`, // plain text body
html: data, // html body
});
console.log(`Message sent: ${info.messageId}`);
});
// Message sent: <[email protected]>
}
const s = async (data) => {
// console.log("data:"+ await SendLastFile())
// console.log(data)
if (data != undefined) main(data).catch(console.error);
};
SendLastFile();