upd
This commit is contained in:
@@ -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;
|
||||
Reference in New Issue
Block a user