-
Notifications
You must be signed in to change notification settings - Fork 4
/
email_rem.js
87 lines (78 loc) · 2.39 KB
/
email_rem.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
83
84
85
86
87
var express = require("express");
var bodyParser = require("body-parser");
const cors = require("cors");
var nodemailer = require("nodemailer");
var mongoose = require("mongoose");
var latest_mess = require("./template_aft.js");
var app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static("public"));
mongoose.connect(
"mongodb+srv://wimpywarlord:[email protected]/<dbname>?retryWrites=true&w=majority",
{
useNewUrlParser: true,
useUnifiedTopology: true,
dbName: "goodmorningGirlfriend",
},
function (err, res) {
if (err) {
console.log(err);
} else {
console.log("CONNECTED");
}
}
);
var userSchema = new mongoose.Schema({
email: String,
phone: String,
question: String,
});
var user = mongoose.model("user", userSchema);
// LOGIC
var everyday_mailingList = [];
async function fetchAllEmails() {
return new Promise((resolve, reject) => {
user.find({}, async function (err, users) {
if (err) {
console.log("NOT FETCHING DATA");
} else {
console.log(users);
for (let i = 0; i < users.length; i++) {
everyday_mailingList.push([users[i].email]);
// console.log(everyday_mailingList);
}
console.log(everyday_mailingList, "$");
resolve(everyday_mailingList);
}
});
});
}
fetchAllEmails().then((everyday_mailingList) => {
console.log(everyday_mailingList, "asddsa");
var transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]",
pass: "Mama!@#123",
},
});
everyday_mailingList.forEach((element) => {
console.log(element);
var mailOptions = {
from: "VinnovateIT",
to: element,
subject: `Join VinnovateIT at 6:00PM on 20th June.`,
html: `${latest_mess}`,
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
});
});
app.listen(process.env.PORT || 8000, function () {
console.log("SERVER 8000 HAS STARTED");
});