with html to xlsx i cant sending mail but pdf OK
-
With html to xlsx I cant send the report as *.xlsx but when I use the chrome pdf I can send the genrated report.pdf file with mail attachement.
I need to send it to mail and to s3 aswell.
const nodemailer = require('nodemailer') async function afterRender(req, res) { const smtpTransport = nodemailer.createTransport({ host: 'smtp.ethereal.email', port: 587, auth: { user: 'yyy', pass: 'xxx' } const mail = { from: "Anand <anandanr@gmail.com>", to: "anandanr@gmail.com", subject: "Sending email from node.js", text: "See the attached report", attachments: [ { // filename: 'rout.xlsx', content: res.content.toString('base64'), type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", filename: "data.xlsx", disposition: "attachment" }], } try { await smtpTransport.sendMail(mail) } finally { smtpTransport.close() } } })
-
There should be no difference. Please elaborate, what error do you get...
-
I am getting this error whiel opening the excel file which has been sentDebug log:
Render request 43 queued for execution and waiting for availible worker Starting rendering request 43 (user: admin) Rendering template { name: daily_total_template, recipe: html-to-xlsx, engine: handlebars, preview: true } Data item not defined for this template. Executing script daily_total_script (beforeRender) Executing script st_file_store_script (beforeRender) Executing script dt_mail_out (beforeRender) Base url not specified, skipping its injection. Rendering engine handlebars Executing recipe html-to-xlsx html-to-xlsx generation is starting html-to-xlsx generation was finished Executing script st_file_store_script (afterRender) Executing script dt_mail_out (afterRender) Skipping storing report. Rendering request 43 finished in 2330 ms
I tried all of these:
attachments: [ { // content: res.content.toString('base64'), // content: Buffer.from(res.content).toString('base64'), filename: 'report.xlsx', // content: Buffer.from(res.content), content: res.content.toString('base64'), // content: Buffer.from(res.content).toString('base64'), disposition: "attachment" , // contentType: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' contentType: 'application/octet-stream', }], }) }
-
Try to check what is inside the xlsx file when it fails to open. Use some notepad.
My guess is that you find there some HTML.This is because you run the report from the studio and the output is html used to preview in excel online. Try to use the "Download" button from the "Run" context menu. That should return plain xlsx and fix the problem.
You can also disable preview in script
function beforeRender(req, res) { req.options.preview = false }
-
This is what there in the xlsx file
<html><head><title>daily_total_template</title><body><iframe style="height:100%;width:100%" src="https://view.officeapps.live.com/op/view.aspx?src=http%3A%2F%2Fjsreport.net%2Ftemp%2F6057feaac4dfce7935c2c6c585303497.xlsx" /></body></html>
I can download the file and open that manually but I need to have that file on mail.
I tied making preview = false, it was only stops to view the stuido
-
Yes, so my suspicion was correct. You have in the
res.content
the HTML dedicated to previewing. I've covered it also in the documentation:
https://jsreport.net/learn/office-preview#scriptsI can download the file and open that manually but I need to have that file on mail.
When you run the report with "Download" button, the
res.content
is then actual xlsx and not the preview HTML, so your script sending the email should work properly.
-
Working ! after
function beforeRender(req, res) { req.options.preview = false }
Thanks..