forked from Isabirye1515/emailServer
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (56 loc) · 1.97 KB
/
index.js
File metadata and controls
69 lines (56 loc) · 1.97 KB
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
require('dotenv').config();
const express = require('express');
const nodemailer = require('nodemailer');
const bodyParser = require('body-parser');
const cors = require('cors');
const app = express();
const port = 3003;
app.use(cors({
origin: ['http://localhost:3000', 'https://livi-fragrances.vercel.app', 'https://eamon-net-bwfd.vercel.app'],
methods: ['POST'],
allowedHeaders: ['Content-Type']
}));
app.use(bodyParser.json());
// Configure nodemailer with environment variables
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: process.env.GMAIL_USER,
pass: process.env.GMAIL_PASS
}
});
app.post('/send-email', (req, res) => {
const { name, email, contact, comment } = req.body;
const mailOptions = {
from: process.env.GMAIL_USER,
to: 'isabiryeelijah15@gmail.com ',
subject: `New Order from ${name}`,
text: `Name: ${name}\nEmail: ${email}\nContact: ${contact}\nComment: ${comment}`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error('Error sending email:', error);
return res.status(500).send({ message: 'Error sending email', error: error.toString() });
}
res.status(200).send({ message: 'Email sent successfully!' });
});
});
app.post('/get-purfumes', (req, res) => {
const { name, phone, email,gender,comment } = req.body;
const mailOptions = {
from: process.env.GMAIL_USER,
to: 'olivenamigadde8@gmail.com',
subject: `New Order from ${name}`,
text: `Name: ${name}|nPhone Number:${phone}\nEmail: ${email}\nGender: ${gender}\nComment: ${comment}`
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error('Error sending email:', error);
return res.status(500).send({ message: 'Error sending email', error: error.toString() });
}
res.status(200).send({ message: 'Email sent successfully!' });
});
});
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});