Custom email send

Sending Data as Text or Attachments

This guide walks through how to collect data, export it as a CSV, email it as an attachment, and then clean up the file automatically.
We'll use the example of gathering current room temperature values and emailing them daily.

Overview of the Process

  1. Create a job to run a query and generate the CSV file.

  2. Create a second job to email the generated CSV to recipients.

  3. Create a third job to delete the CSV file after the email is sent.

Each job should be scheduled so they run in the correct order and with a short buffer between them.

1. Create the CSV File

Query Explanation

We want to retrieve all points named "Room Temp" along with their current value and references (site, floor, equipment). The extra references help distinguish identical point names.

Breakdown of the query:

  • readAll(navName=="Room Temp")
    Returns all points whose navName is Room Temp.

  • .keepCols([...])
    Limits the output to the fields we care about:
    navName, curVal, siteRef, floorRef, equipRef.

  • .reorderCols([...])
    Ensures the columns appear in a specific order instead of randomly.

  • .ioWriteCsv(io/My Temps.csv)
    Writes the data to a CSV file in the io directory.
    You may rename the file as needed.

Full Query

readAll(navName=="Room Temp") .keepCols(["navName", "curVal", "floorRef", "equipRef", "siteRef"]) .reorderCols(["navName","curVal", "siteRef", "floorRef", "equipRef"]) .ioWriteCsv(`io/My Temps.csv`)

Create the CSV Job

  1. Go to DB Builder

  2. Open Jobs Tree

  3. Click Add

  4. Enter a job name

  5. Paste the full query into the Function field

  6. Set a schedule (make sure it runs before the email job)

  7. Save

2. Email the CSV Attachment

Using emailSend()

The function format is:

emailSend(recipients, subject, content, attachments)

Parameters:

  • recipients

    • Single email: "email@example.com"

    • Multiple emails: ["email1@example.com","email2@example.com"]

  • subject

  • email body text

  • attachment path (optional)

Full Query Example

emailSend( "rickyv@j2inn.com", "My Temps", "Attached you can find the Room Temps.", `io/My Temps.csv` )

Create the Email Job

  1. Go to DB Builder

  2. Open Jobs Tree

  3. Click Add

  4. Enter a job name

  5. Paste the email query into the Function field

  6. Set a schedule (ensure it runs after the CSV job, but before the cleanup job)

  7. Save


3. Delete the CSV File

To prevent build-up of files in the io directory, create a cleanup job.

Full Query

ioDelete(`io/My Temps.csv`)

Create the Delete Job

  1. Go to DB Builder

  2. Open Jobs Tree

  3. Click Add

  4. Enter a job name

  5. Paste the delete query into the Function field

  6. Set the schedule (ensure it runs after the email job)

  7. Save