forked from ACM-IGDTUW/Open-Source-Challenge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
61 lines (51 loc) · 1.66 KB
/
app.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
var express = require("express"),
bodyParser = require("body-parser"),
exphbs = require("express-handlebars"),
nodemailer = require("nodemailer"),
app = express();
app.use(express.static(__dirname + "/public"));
// app.use(express.static(path.join(__dirname,"public")));
app.engine("handlebars", exphbs());
app.set("view engine", "handlebars");
app.use(bodyParser.urlencoded({extended: false}));
app.use(bodyParser.json());
app.get("/", async function(req, res) {
res.render("events.ejs");
});
app.get("/register", async function(req, res) {
res.render("contact");
});
app.post("/send", function(req, res) {
console.log("SENT!");
// create reusable transporter object using the default SMTP transport
let transporter = nodemailer.createTransport({
host: 'smtp.gmail.com',
port: 587,
secure: false, // true for 465, false for other ports
// service: 'gmail',
auth: {
user: '#',
pass: '#'
},
tls:{
rejectUnauthorized:false
}
});
// setup email data with unicode symbols
let mailOptions = {
from: '"ACM" <email@address>', // sender address
to: 'req.body.email', // list of receivers
subject: 'req.body.event', // Subject line
text: 'Welcome to the event. The schedule is.... ', // plain text body
};
// send mail with defined transport object
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
return console.log(error);
}
// console.log('Message sent: %s', info.messageId);
// console.log('Preview URL: %s', nodemailer.getTestMessageUrl(info));
res.render('contact', {msg:'Email has been sent'});
});
});
module.exports = app;