-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
60 lines (52 loc) · 1.56 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
const cors = require('cors');
const nodemailer = require('nodemailer');
const express = require('express');
const bodyParser = require('body-parser')
const app = express()
const path = require('path');
const PORT = process.env.PORT || 5000;
const smtp_login = process.env.SMTP_LOGIN
const smtp_password = process.env.SMTP_PASSWORD
app.use(cors())
app.use(bodyParser.urlencoded({extended: false}))
app.use(bodyParser.json())
express()
.use(express.static(path.join(__dirname, 'public')))
.set('views', path.join(__dirname, 'views'))
.set('view engine', 'ejs')
let transporter = nodemailer.createTransport({
service: 'Yandex',
auth: {
user: smtp_login,
pass: smtp_password,
},
});
app.post('/sendPost', async (req, res) => {
let {email, name, message} = req.body
//check data
console.log(name)
console.log(email)
console.log(message)
let mailOptions = {
from: smtp_login,
to: '[email protected]',
subject: 'HR Message from portfolio',
html: `<div>
<div>email:${email}</div>
<div>name: ${name}</div>
<div>message: ${message}</div>
</div>`,
}
let info = await transporter.sendMail(mailOptions, function (err, data) {
if (err) {
console.log('Error Occurs', err)
} else {
console.log('Email sent!!!')
}
});
res.send(req.body)
})
.get('/', (req, res) => res.send(
`<div>hello</div>`
))
.listen(PORT, () => console.log(`Listening on ${PORT}`));