-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (50 loc) · 1.18 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const express = require('express');
const bodyParser = require("body-parser");
const nodemailer = require('nodemailer');
const cors = require('cors');
const app=express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended:true}));
app.use(cors());
app.get('/', ()=>{
res.send('welcome to my forma');
})
app.post('/api/forma', (req,res)=>{
let data=req.body;
let smtpTransport = nodemailer.createTransport({
service:'Gmail' ,
port:465,
auth:{
user:'odkolas@gmail.com',
pass:"galopoula@21@21"
}
});
let mailOptions={
from:data.email,
to:'odkolas@gmail.com',
subject:`Message from ${data.name}`,
html:`
<h3>Informations</h3>
<ul>
<li>Name: ${data.name}</li>
<li>Lastname: ${data.lastname}</li>
<li>Email: ${data.email}</li>
</ul>
<h3>Message</h3>
<p>${data.message}</p>
`
};
smtpTransport.sendMail(mailOptions, (error, response)=>{
if(error){
res.send(error)
}
else{
res.send('Success')
}
smtpTransport.close();
})
})
const PORT = process.env.PORT||3001;
app.listen(PORT,()=>{
console.log(`server listening at port ${PORT}`);
})