-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (48 loc) · 1.72 KB
/
server.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
require("dotenv").config()
const express = require("express");
const app = express();
const nodemailer = require("nodemailer");
const SENDER_MAIL = process.env.SENDER_MAIL;
const RECEIVER_MAIL = process.env.RECEIVER_MAIL;
const transporter = nodemailer.createTransport({
service:"gmail",
auth:{
user:SENDER_MAIL,
pass:process.env.APP_PASS
}
});
const mailoptions = {
from:SENDER_MAIL,
}
app.use(express.static("./views"));
app.use(express.json());
app.use(express.urlencoded({extended:false}));
app.get("/", (req,res) => {
res.render("index.html");
})
app.post("/help", (req,res) => {
const {latitude, longitude} = req.body.location;
console.log("Data Received!")
console.log("Latitude: "+latitude);
console.log("Longitude: "+longitude);
// res.send("Help reached Server!");
const mailoptions = {
from:SENDER_MAIL,
to:RECEIVER_MAIL,
subject:"Test Helpline Text from Nodemailer",
html:`<h2>This is a test Mail from Nodemailer</h2><br> Latitude: ${latitude} <br> Longitude: ${longitude}<br><br><a href = "http://maps.google.com/maps?q=${latitude},${longitude}">Click here to View on Map</a><br><iframe src = "http://maps.google.com/maps?q=${latitude},${longitude}"></iframe>`
}
transporter.sendMail(mailoptions, (err, info) => {
if(err){
console.log(err);
res.status(500).send("Internel Server Error Occured");
}else{
console.log("Email sent: "+info.response);
res.status(201).send("Email Sent Successfully!!");
}
});
})
const PORT = 5000;
app.listen(PORT, () => {
console.log(`[SERVER STARTED] http://localhost:${PORT}`);
});