This commit is contained in:
2024-11-12 14:34:17 +05:00
parent 312082d94c
commit 1cf520814e
8 changed files with 205 additions and 20 deletions
+41
View File
@@ -0,0 +1,41 @@
import { Router } from "express";
import { createTransport } from "nodemailer";
import fs from "fs";
const router = Router();
router.post("/", async (req, res) => {
console.log(req.body);
try {
const transporter = createTransport({
host: req.body.host,
port: req.body.port,
secure: true, // true for 465, false for other ports
auth: {
user: req.body.from, // generated ethereal user
pass: req.body.password, // generated ethereal password
},
});
const files = fs.readdirSync(req.body.path);
// send mail with defined transport object
await transporter.sendMail({
from: req.body.from, // sender address
to: req.body.to, // list of receivers
subject: req.body.subject, // Subject line
html: req.body.text, // html body
attachments: files.map((file) => ({ path: `${req.body.path}/${file}` })), // attachment files
});
return res.json({ ok: 1 });
} catch (error) {
console.log(error);
return res.json({ error: 1 });
}
});
const sendMessageRoute = router;
export default sendMessageRoute;