-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmailer.cjs
More file actions
54 lines (46 loc) · 1.22 KB
/
Copy pathmailer.cjs
File metadata and controls
54 lines (46 loc) · 1.22 KB
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
require("dotenv").config();
const path = require("path");
const { DateTime } = require("luxon");
const nodemailer = require("nodemailer");
// get report date
const lineByLine = require("n-readlines");
const { cwd } = require("process");
const liner = new lineByLine("LastReportDate.txt");
let line;
let lineNumber = 0;
let reportDate = "";
while ((line = liner.next())) {
if (lineNumber === 0) {
reportDate = line.toString();
}
lineNumber++;
}
const file = path.join(cwd(), "WaitingList.csv");
console.log(file);
const todaysDate = DateTime.now().toFormat("MM-dd-yyyy");
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL_FROM_ADDRESS,
pass: process.env.EMAIL_PASSWORD,
},
});
const mailOptions = {
from: process.env.EMAIL_FROM_ADDRESS,
to: process.env.EMAIL_TO_ADDRESS,
subject: `Transplant Waiting List ${todaysDate}`,
text: `Transplant Waiting List Data through ${reportDate}`,
attachments: [
{
filename: "TransplantWaitingList.csv",
path: file,
},
],
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Transplant Email sent: " + info.response);
}
});