-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
64 lines (56 loc) · 1.43 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"use strict";
const express = require("express");
const cors = require("cors");
const nodemailer = require("nodemailer");
require("dotenv").config();
const PORT = process.env.PORT || 8080;
const app = express();
app.use(cors());
app.use(
express.urlencoded({
extend: false,
})
);
app.use(express.json());
let transporter = nodemailer.createTransport({
// service: "gmail",
host: "ssl0.ovh.net",
port: 587,
auth: {
user: process.env.EMAIL,
pass: process.env.PASSWORD,
},
});
transporter.verify((err, success) => {
err
? console.log(err)
: console.log(`Server is ready to take messages: ${success}`);
});
app.get("/cv", (req, res) => {
const file = `${__dirname}/resources/CVJavascript.pdf`;
console.log(file);
res.download(file);
});
app.post("/send", (req, res) => {
const { name, email, message } = req.body;
console.log("Data : ", req.body);
let mailOptions = {
sender: name,
from: "[email protected]",
to: "[email protected]",
subject: `${name} - ${email}`,
text: message,
};
transporter.sendMail(mailOptions, (err, data) => {
if (err) {
res.status(500).json({ message: "Internal error", error: `${err}` });
console.log(`Error : ${err}`);
} else {
console.log("Email sent !");
res.status(200).json({ message: "Email sent" });
}
});
});
app.listen(PORT, () => {
console.log("Server starting on PORT, ", 8080);
});