I have a contact form and i want to upload a html template using the input file and send it with Nodemailer. I have used formidable to get a temporary path but im not able to pass this parameter to the HTML tag of sendMail. How can i archive this ?
This is my current app.js
const express = require('express');
const formidable = require('formidable');
var fs = require('fs');
const port = process.env.PORT || 3000;
const app = express();
app.get('/', (req, res) => {
res.send(`<h2>With<code>"express"</code>
npmpackage</h2>
<form action="/api/upload" enctype="multipart/form-data" method="post">
<div>Text field title:<input type="text" name="title"/></div>
<div>File:<input type="file" name="someExpressFiles" multiple="multiple"/>
</div>
<input type="submit" value="Upload"/>
</form>`);
});
app.post('/api/upload', (req, res, next) => {
const form = new formidable.IncomingForm({ multiples: true });
form.parse(req, (err, fields, files) => {
if (err) { next(err); return; }
res.json({
fields, files
});
});
async function main() {
let testAccount = await nodemailer.createTestAccount();
let transporter = nodemailer.createTransport({
host: "smtp.ethereal.email",
port: 587,
secure: false,
auth: {
user: testAccount.user,
pass: testAccount.pass,
},
});
let info = await transporter.sendMail({
from: '"Fred Foo