-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathapp.js
More file actions
57 lines (47 loc) · 1.51 KB
/
Copy pathapp.js
File metadata and controls
57 lines (47 loc) · 1.51 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
const express = require("express");
const cors = require("cors");
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");
const details = require("./details.json");
const app = express();
app.use(cors({ origin: "*" }));
app.use(bodyParser.json());
app.listen(3000, () => {
console.log("The server started on port 3000 !!!!!!");
});
app.get("/", (req, res) => {
res.send(
"<h1 style='text-align: center'>Wellcome to FunOfHeuristic <br><br>😃👻😃👻😃👻😃👻😃</h1>"
);
});
app.post("/sendmail", (req, res) => {
console.log("request came");
let user = req.body;
sendMail(user, info => {
console.log(`The mail has beed send 😃 and the id is ${info.messageId}`);
res.send(info);
});
});
async function sendMail(user, callback) {
// 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
auth: {
user: details.email,
pass: details.password
}
});
let mailOptions = {
from: '"Fun Of Heuristic"<example.gimail.com>', // sender address
to: user.email, // list of receivers
subject: "Wellcome to Fun Of Heuristic 👻", // Subject line
html: `<h1>Hi ${user.name}</h1><br>
<h4>Thanks for joining us</h4>`
};
// send mail with defined transport object
let info = await transporter.sendMail(mailOptions);
callback(info);
}
// main().catch(console.error);