-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.js
50 lines (41 loc) · 1.39 KB
/
message.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
const bodyParser = require('body-parser')
const cors = require('cors')
const express = require('express')
const app = express()
// create reusable transporter object using the default SMTP transport
const nodemailer = require('nodemailer')
let port = process.env.PORT || 3000
let smtp_login = process.env.SMTP_LOGIN || '---'
let smtp_password = process.env.SMTP_PASSWORD || '---'
app.options('*', cors())
app.use(cors({ origin: 'https://tomatovan.github.io' }))
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }))
// parse application/json
app.use(bodyParser.json())
let transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: smtp_login, // generated ethereal user
pass: smtp_password, // generated ethereal password
},
})
app.get('/', function (req, res) {
res.send('Hello World')
})
app.post('/sendMessage', async (req, res) => {
let { name, email, message } = req.body.data
// send mail with defined transport object
let info = await transporter.sendMail({
from: `"${name}" <${email}>`, // sender address
to: '<[email protected]>', // list of receivers
subject: 'Message from CV form ✔', // Subject line
html: `<b>Letter from CV:</b>
<div>name: ${name}</div>
<div>contacts: ${email}</div>
<div>message: ${message}</div>`,
})
})
app.listen(port, () => {
console.log(`Example app listening!, ${port}`)
})