-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
47 lines (41 loc) · 1.23 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
45
46
47
// // BISMILLAH
const express = require("express");
const app = express();
const path = require("path");
const nodemailer = require("nodemailer");
const pug = require("pug");
const bodyParser = require("body-parser");
const port = process.env.PORT || 5000;
app.set("view engine", "pug");
app.set("views", path.join(__dirname, "views"));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.get("/", (req, res) => {
res.status(200).render("page", { title: "Send an Email!" });
});
app.post("/send-email", (req, res, err) => {
var transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]",
pass: "yourPass",
},
});
const mailOptions = {
from: `"UzbekDev98" <[email protected]>`,
to: req.body.to,
subject: req.body.subject,
text: req.body.body,
};
transporter.sendMail(mailOptions, function(error, info) {
if (error) {
console.log(error);
} else {
console.log("Email sent: " + info.response);
}
});
res.render("page", { title: "Message has sent!" });
});
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
});