-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (40 loc) · 1.29 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
const csv = require("csv-parser");
const fs = require("fs");
var nodemailer = require("nodemailer");
var smtpTransport = nodemailer.createTransport({
host: "smtp.office365.com", // Office 365 server, change this when using other mail services
secureConnection: false,
port: 587,
auth: {
user: "[email protected]", // your actual email
pass: "password", // your actual password
},
});
fs.createReadStream("emails.csv")
.pipe(csv())
.on("data", (row) => {
console.log(row.email);
var mailOptions = {
from: "[email protected]", // sender address
to: row.email, // replace with the recipient's email address
cc: "[email protected]", // Put yourself in cc to get a copy of the email and revert back to your mails.
subject: "Subject of the E-Mail", // Subject line
html: `<p> Body of the email </p>`, // html body with multiple paragraphs
attachments: [
{
filename: "filename.pdf",
path: "path/to/file/filename.pdf",
},
],
};
smtpTransport.sendMail(mailOptions, function (error, response) {
if (error) {
console.log(error);
} else {
console.log("Message sent: " + response.message);
}
});
})
.on("end", () => {
console.log("Emails sent successfully");
});