External email service integration

Hello, good morning.

I was reading the Tago documentation about setting up an external email service since, starting January 1st, Tago will no longer provide native support for email sending. I came across some questions. In my analysis, I have several email sending requests, many with different recipients and messages. From what I understood in the provided documentation, I need to create an action so that, when a condition is met, the email is triggered. However, I noticed that in Actions, the recipients and messages are static, not dynamic. How can I work around this issue?

No no, if you already have a working analysis run setup, you need to modify your code a little bit. I assume you already have a working SMTP server or mailing service.

For example, following the preset example script that generates a .pdf file and sends it via mail:

const { Analysis, Device, Services, Utils } = require("@tago-io/sdk");const envVars = Utils.envToJson(context.environment);// Start the email serviceconst emailService = new Services({ token: context.token }).email;// Send the email.await emailService.send({  to: envVars.email,  subject: "Exported File from TagoIO",  message: "This is an example of a body message",  attachment: {    archive: pdf_base64.result,    type: "base64",    filename: "exportedfile.pdf",  },});

You need to set up your SMTP credentials in the ‘Secrets’ sections of your TagoIO account, and then enable the secret in the ‘Access’ module, giving permission to all your scripts that needed these credentials.

Then, in your script, you need to access your SMTP credentials (in the environment), change the method of your mailService, and add your credentials in the object.

const { Analysis, Device, Services, Utils } = require("@tago-io/sdk");const envVars = Utils.envToJson(context.environment);// Start the email serviceconst emailService = new Services({ token: context.token }).smtp;// Send the email.await emailService.send({  from: "account@your-mail.com",  smtp_secret: envVars.YOUR_SMTP_SECRET,  to: envVars.email,  subject: "Exported File from TagoIO",  message: "This is an example of a body message",  attachment: {    archive: pdf_base64.result,    type: "base64",    filename: "exportedfile.pdf",  },});

I noted that with the new .smtp method you need to specify also your ‘from’ parameter, so you need a working mail (but perhaps it’s a skill issue on my end).

My code is similar to the one you sent. However, when modifying the instance to use SMTP, an error occurs.

Has anyone used the SendGrid in an analysis with attachment successfully? I keep getting authorization denied, but i can send it through the old tago service just fine.

zsu[@user:10069644160]zsu do you have your SDK updated? I had to update all my external analyses as well. Try that.