-
Notifications
You must be signed in to change notification settings - Fork 0
/
email.js
34 lines (28 loc) · 953 Bytes
/
email.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
// middleware/email.js
import nodemailer from 'nodemailer';
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]', // Your Gmail email address
pass: 'your_password' // Your Gmail password
}
});
const sendEmailMiddleware = (req, res, next) => {
const { email, jobTitle } = req.body;
const mailOptions = {
from: '[email protected]',
to: email,
subject: 'Job Application Confirmation',
text: `Thank you for applying for the job '${jobTitle}'. Your application has been received.`,
};
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log(error);
res.status(500).json({ success: false, message: "Failed to send email" });
} else {
console.log('Email sent: ' + info.response);
res.status(200).json({ success: true, message: "Email sent successfully" });
}
});
};
export default sendEmailMiddleware;