-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
59 lines (54 loc) · 1.64 KB
/
Copy pathindex.js
File metadata and controls
59 lines (54 loc) · 1.64 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
55
56
57
58
59
// Required libraries
const nodemailer = require('nodemailer');
const fs = require('file-system');
// Change path to your data file if you want
const DATABASE_PATH = `${__dirname}/test.txt`;
// Your email and smtp data
const SENDER_EMAIL = '';
const SMTP_SECURE_PASSWORD = '';
// This function is necessary to parse data from your txt data file
// you can configure it in way you need to
// Actual configruation is:
// Each line is an another user
// In each line, a single word is a separate piece of data such as first name, last name, email address, etc.
const parseTxt = txt => {
const data = [];
txt.split('\n').forEach(user => {
const [firstName, lastName, email] = user.split(' ');
data.push({
id: data.length + 1,
firstName,
lastName,
email
});
});
return data;
};
async function main() {
// Reading file
const data = fs.readFileSync(DATABASE_PATH, 'utf8');
// Parsing data
const DATABASE = parseTxt(data);
// Creating transporter object
let transporter = nodemailer.createTransport({
service: 'gmail',
host: 'smtp.gmail.com',
secure: false,
auth: {
user: SENDER_EMAIL,
pass: SMTP_SECURE_PASSWORD,
},
});
for (let i = 0; i < DATABASE.length; i++) {
// Parsed data from txt file
const { email } = DATABASE[i];
let info = await transporter.sendMail({
from: '"Sender" <SenderEmail>', // Important to paste sender email in <> in order to not get in spam
to: email, // email form txt file
subject: "Test",
text: "Test"
});
console.log(`Message sent: ${info.messageId}. Destination: ${email}`);
}
}
main().catch(console.error);