-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
47 lines (38 loc) · 1.18 KB
/
server.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
const nodemailer = require('nodemailer');
// Create a transporter using Gmail's SMTP settings
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]',
pass: '123Bffs123',
},
});
function sendEmail(name, email) {
const mailOptions = {
from: '[email protected]',
to: '[email protected]', // Your email address to receive the RSVP emails
subject: 'New RSVP',
text: `Name: ${name}\nEmail: ${email}`,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error(error);
} else {
console.log('Email sent: ' + info.response);
}
});
}
const express = require('express');
const app = express();
app.use(express.urlencoded({ extended: true }));
app.post('/rsvp', (req, res) => {
const name = req.body.name;
const email = req.body.email;
// Call the sendEmail function with the attendee's details
sendEmail(name, email);
// Send a confirmation email to the attendee (code to be added later)
res.send('RSVP submitted successfully!');
});
app.listen(3000, () => {
console.log('Server started on port 3000');
});