-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
39 lines (32 loc) · 890 Bytes
/
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
const bodyParser = require("body-parser");
const express = require("express");
const nodemailer = require("nodemailer");
const cors = require("cors");
require("dotenv").config()
const app = express();
app.use(cors());
app.use(bodyParser.json());
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: process.env.EMAIL ,
pass: process.env.PASSWORD ,
},
});
app.post("/send-mail", (req, res) => {
const { name, email, subject, message } = req.body;
const mailOptions = {
from: email,
to: "[email protected]",
subject,
text: message,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
res.status(500).send(`error generating email ${error}`);
} else {
res.status(200).send(`email sending success ${info}`);
}
});
});
app.listen(5000, () => console.log("server started"));