const express = require('express'); const nodemailer = require('nodemailer'); const bodyParser = require('body-parser'); const app = express(); const port = 3000; app.use(bodyParser.urlencoded({ extended: true })); // Set up the email transporter const transporter = nodemailer.createTransport({ service: 'gmail', // Use your own email service here auth: { user: 'youremail@gmail.com', pass: 'yourpassword', } }); // Endpoint to handle sending email app.post('/send', (req, res) => { const { to, subject, body } = req.body; const mailOptions = { from: 'youremail@gmail.com', to: to, subject: subject, text: body, }; transporter.sendMail(mailOptions, (error, info) => { if (error) { return res.status(500).send(error.toString()); } res.send('Email sent: ' + info.response); }); }); app.listen(port, () => { console.log(`Server is running at http://localhost:${port}`); });