-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (48 loc) · 1.39 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
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.post('/api/form', (req, res) => {
console.log(req.body);
//Formating content to be send
var emailcontent = `<h3> Contact Details</h3>
<ul>
<li>name: ${req.body.name}</li>
<li>email : ${req.body.email}</li>
</ul>
<h2>Message</h2>
<p>message: ${req.body.subject}</p>
`;
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: 'XYZ',
},
tls: {
rejectUnauthorized: false,
},
});
//Preparing the mailOptions object
var mailOptions = {
from: '[email protected]',
to: '[email protected]',
subject: 'New Message',
text: req.body.subject,
html: emailcontent,
};
//Sending email using transporter function
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
});
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`server listening on port ${PORT}`);
});