Email Reports Daily



  • I have several reports set up to send daily attached to an email. I recently added another report, set up the same way as the others, but only the new report isn't emailed daily. Please advise how to ensure the new report is also sent in the daily batch with the others.

    Below is the afterRender function used to send the mail:

    const nodemailer = require('nodemailer')
    async function afterRender(req, res) {
        const transporter = nodemailer.createTransport({
          service: 'SendGrid',
          auth: {
              user: '***',
              pass: '**********'
          }
        });
    
        await transporter.sendMail({
          from: "admin@address.com",
          to: "me@address.com",
          subject: "mySubject",
          text: "",
          html: "",
          attachments: [
          {  
            filename: 'myReport.csv',
            content: Buffer.from(res.content)
          }],
        })       
    }
    


  • Hi,

    so you use jsreport scheduling with a daily cron and the template has the mentioned script attached?

    Does it send an email when you trigger the template run?

    Jan



  • Hi Jan,

    Yes, when I run the template the email sends as expected. I had not set up the other reports, and I cannot find in any of the files where the cron is controlled. None of the files contain the cron attribute listed in the jsReport docs, but the person that created the reports insists everything is within jsReport. e.g. not running a script through task manager on the machine that hosts our jsReport.

    Each report is comprised of three files: the Report file that generates the report, the Schedule file which sends the email, and the SQL file that contains the query for the report. None of those files set the cron attribute to run daily, and yet all but my new report run daily.



  • Please check this article
    https://jsreport.net/learn/periodical-report-sending-through-email

    It seems that either your new template doesn't reference the script, that is sending the email.
    Or you don't have a schedule entity, that triggers based on CRON the template rendering.



  • Hi Jan,

    The template does reference the script, but the Schedule entity isn't present in my instance of jsReport (see image). However, the scheduling extension is in my instance (see second image). Am I missing something in the setup to be able to create a schedule entity?

    0_1625248928405_upload-5a71672f-da96-4d79-b69a-e6136c86c466

    0_1625249042860_upload-55dd0a88-78da-4d09-96e7-967b4af5c843



  • In case the authentication is enabled, you need to be logged in with admin credentials, which you can find in the jsreport configuration.



  • hmmm, the admin credentials I had been provided with (also found in the config file) throw me an "invalid password or user doesn't exist" error



  • Follow up here Jan, the credentials found in the config file login on the dev instance of our jsReport, but not the Production instance.



  • TL/DR; If you need to create a schedule for your reports, make sure you are logged in as the admin user. Those credentials can be found in the jsreport.config.json file if authentication is enabled.

    Hi Jan,

    I dug through the commit history in our jsReport repository, and found the admin credentials I needed. It's unclear to me how the production instance of our jsReport is pulling the configuration info, as there is only a single branch with the jsreport.config.json file in the repo, and it points to our development instance; however, with the correct credentials I was able to create a schedule for my new report.

    Appreciate your help, I consider this matter/topic closed.



  • Great, thank you for sharing the resolution.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.