Send email in "Generate PDF report"

Hi,

I am wanting to send a PDF report to an email by typing in an input form. But as far as I know, it is necessary to dictate a fixed email in “Environmental variables”. If not, it returns: email environment variable not found.

My question is how to prevent my analysis from just sending the PDF to the fixed email in the environmental variables, and how to make it send to the email typed in an input form.

As a sample code I used “Generate pdf report and send via email” in Tago. And I followed the tutorial: https://community.tago.io/t/how-to-generate-a-beautiful-pdf-using-tagoio/389

You would need to section of the code where it gets the email from the environment variable.

Usually, you want to get this from the scope or from the device bucket.
For the scope, it means you’re triggering the analysis from a Widget like an Input Form, and every time you press “submit” button it runs the analysis.

So, for the code you’ll need to do something like this:

const email_variable = scope.find(data => data.variable === "email_variable_from_the_form");
const email = email_variable.value;

If you want to get from the device bucket, which means you’re probably running this analysis by a scheduled action, you will need to provide the device-token.

const { Device } = require("@tago-io/sdk");
...
const device = new Device({ token: "your-device-token" });

// automatically get first data from the array. getData alwats return an array [{ variable, value, unit... }];
const [email_variable] = await device.getData({ variables: "your_email_variable", qty: 1 });
const email = email_variable.value;

If you want to automatically get the token from a device, you will need to code this. Some instruction is provided in this post: Passing Parameters to Analysis (ex. Device_token) - Analysis - TagoIO Community

1 Like