-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
59 lines (47 loc) · 1.28 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
58
59
const express = require('express');
const app = express();
const nodemailer = require('nodemailer');
const PORT = process.env.PORT || 5000;
// Middleware
app.use(express.static('public'));
app.use(express.json());
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html')
})
app.post('/', (req, res) => {
let transporter = nodemailer.createTransport({
host: 'smtp.mail.com',
port: 587,
secure: false,
auth: {
user: "bla bla bla",
pass: "bulbulbul"
}
})
const mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: `Message from ${req.body.name} - ${req.body.email}`,
text: req.body.message
}
// verify connection configuration
transporter.verify(function (error, success) {
if (error) {
console.log(error);
} else {
console.log("Server is ready to take our messages");
}
});
transporter.sendMail(mailOptions, (error, info) => {
if(error) {
console.log(error);
res.send('error')
} else {
console.log('Email sent' + info.response)
res.send('success')
}
})
})
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`)
})