-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (28 loc) · 891 Bytes
/
app.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
const express = require('express');
const bodyParser = require('body-parser');
const nodemailer = require('nodemailer');
const app = express();
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/submit-form', (req, res) => {
let formData = req.body;
sendEmail(formData)
.then(() => res.send('Email sent successfully!'))
.catch(err => res.status(500).send(err.message));
});
function sendEmail(formData) {
let transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'email',
pass: 'password'
}
});
let mailOptions = {
from: 'email',
to: 'email',
subject: 'Form Submission',
text: JSON.stringify(formData, null, 2)
};
return transporter.sendMail(mailOptions);
}
app.listen(3000, () => console.log('Server listening on port 3000'));