-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
84 lines (78 loc) · 2.4 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
"use strict";
const nodemailer = require("nodemailer");
const express = require("express");
const cors = require("cors");
require("dotenv").config();
const app = express();
app.use(cors({ origin: "https://flexfintx.com" }));
app.use(express.json());
let transporter = nodemailer.createTransport({
host: process.env.NODEMAILER_HOST,
port: process.env.NODEMAILER_PORT,
secure: process.env.NODEMAILER_SECURE,
auth: {
user: process.env.NODEMAILER_USER,
pass: process.env.NODEMAILER_PASS,
},
});
app.post("/mail/contact", async (req, res) => {
if (req.body.email && req.body.name && req.body.message) {
transporter.sendMail(
{
from: '"FlexFinTx" <[email protected]>',
to: "[email protected]",
subject: `Contact Form: ${req.body.name} - ${req.body.email}`,
text: `
Received a contact form submission.
Name: ${req.body.name}
Email: ${req.body.email}
Message: ${req.body.message}
`,
},
(err) => {
if (err) {
console.error(`Error sending email from ${req.body.email}`);
return res
.status(500)
.json({ error: true, message: "Could not send email " });
} else {
return res.status(200).json({ error: false, message: "Sucess" });
}
}
);
} else {
res.status(400).json({ message: "Please fill all the fields" });
}
});
app.post("/mail/quote", async (req, res) => {
if (req.body.email && req.body.name && req.body.message) {
transporter.sendMail(
{
from: '"FlexFinTx" <[email protected]>',
to: "[email protected]",
subject: `Quote Request: ${req.body.name} - ${req.body.email}`,
text: `
Received a request quote form submission.
Name: ${req.body.name}
Email: ${req.body.email}
Message: ${req.body.message}
`,
},
(err) => {
if (err) {
console.error(`Error sending email from ${req.body.email}`);
return res
.status(500)
.json({ error: true, message: "Could not send email " });
} else {
return res.status(200).json({ error: false, message: "Sucess" });
}
}
);
} else {
res.status(400).json({ message: "Please fill all the fields" });
}
});
app.listen(process.env.API_PORT, () => {
console.log(`web-api listening on port ${process.env.API_PORT}!`);
});