-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
57 lines (43 loc) · 1.31 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
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const nodemailer = require('nodemailer');
const app = express();
const PORT = 3001;
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(cors());
app.post('/send-email', (req, res) => {
const { name, email, message } = req.body;
// transporter object
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'qzsy oisx kmzu zion ' //pasword
}
});
let mailOptions = {
from: email,
to: '[email protected]',
subject: 'Website - New Message from ' + name,
text: message,
replyTo: email //actual senders email
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
res.send('error');
} else {
console.log("Email Sent: " + info.response);
res.send({ message: 'success', info: info.response });
}
});
});
app.use((err, req, res, next) => {
console.error(err.stack);
res.status(500).send('error');
});
app.listen(PORT, '0.0.0.0', () => {
console.log(`Server is running on port ${PORT}`);
});