I wrote a basic script that reads a JSON file and converts it to an HTML table using json2html. I then email this table using nodemailer.
The code works to send the table in an email. However, I would like to add some styling to the table and am yet to find a good solution.
Below is the code for my HTML Table creation:
var jsonText = fs.readFileSync('file.json').toString();
var data = JSON.parse(jsonText);
var tmpl = "<td>${firstName}</td><td>${lastName}</td><td>${email}</td><td>${skills}</td><td>${linkedin}</td><td>${github}</td>"
var transform = {'tag':'tr','html':tmpl};
data.forEach(function(item) {
if (data.skills) {
data.skills = data.skills.join(',' + ' ');
}
})
var resp = "<table>" + json2html.transform(data,transform) + "</table>";
Here is sendmail portion of my nodemailer code for reference:
transporter.sendMail({
from: 'email@gmail.com',
to: 'email@gmail.com',
subject: 'TEST',
html: resp
});
Aucun commentaire:
Enregistrer un commentaire