UniFi Online/Offline Emails with Autotask
This tutorial walks through building a workflow that processes device offline and device online alert emails from Ubiquity UniFi. When a device goes offline, a new Autotask ticket is created. When the device reconnects, Email2AT locates that original ticket, adds a note, and closes it.
Part 1 covers the core workflow. Part 2 covers how to associate tickets to the correct Autotask account based on the sender's email address.
Overview
UniFi sends two types of alert emails:
| Alert | Subject line | What the workflow does |
|---|---|---|
| Device offline | Device Offline | Creates a new Autotask ticket for the device |
| Device reconnected | Device Reconnected | Finds the open offline ticket and closes it with a note |
The key challenge is connecting these two separate emails to a single ticket. The workflow solves this by extracting the device name from each email and embedding it in the ticket description. When the online alert arrives, Email2AT queries Autotask for an open ticket containing that device name and updates it.
Related pages:
Part 1: Create and Close Tickets for Offline/Online Alerts
Before You Start
Create a dedicated mailbox for UniFi alerts. Do not use your general support mailbox.
- Navigate to Email2AT and click Hosted Mailboxes
- Create a new mailbox, for example:
[email protected] - Configure your UniFi system or controller to send alert emails to this address
Send a test offline and online alert through before building the rules. With no rules in the mailbox yet, the emails will be received and logged in History but not processed. You can then open those history entries to see exactly how Email2AT parsed each email, which makes writing the extraction logic much easier.
Rule 1: Process Offline Alerts
This rule fires only when a device goes offline and creates a new ticket.
Add the rule
- In your mailbox, click Add New Rule
- Name it
Process UniFi Offline Alerts - Set the Expression so the rule only fires for offline emails: subject equals
Device Offline
Action 1: Extract the device name
- Click Add New Action, select Render Text and Store as Variable, click OK
- Name the step
Extract Device Name - In the text field, enter:
{{after_string email.body "Device Name: " flags="tn"}}
This extracts everything after Device Name: in the email body. The t flag trims whitespace and the n flag stops at the next newline, so you get just the device name (for example, ACME-AP-01) and nothing else.
- In Store results in variable, enter
device_name - Set Only perform this action if to always run (no condition needed on this step)
Before building the extraction, open the offline email in History and look at the plain text body exactly as Email2AT received it. Find the Device Name: label and confirm the format. UniFi alert emails may vary slightly depending on your controller version.
Action 2: Create the ticket
- Click Add New Action, select API: Create an Object, click OK
- Name the step
Create New Ticket - Set Entity Type to
Ticket - Set Only perform this action if:
custom.device_nameis not empty - Configure the ticket fields:
Ticket fields:
| Field | Value |
|---|---|
| AccountID | Your zero account (unlock the field and enter 0), or see Part 2 for account matching |
| Status | New |
| Priority | Set as appropriate for alert severity |
| QueueID | Your monitoring alerts queue |
| Title | {{email.subject}} |
| Description | {{email.body}} followed by a blank line and [UniFi Device: {{custom.device_name}}] |
The [UniFi Device: ACME-AP-01] tag at the end of the description is how the online rule will find this ticket later. When the online alert arrives, Email2AT searches for an open ticket whose description contains [UniFi Device: followed by the device name from the online email. This tag ensures the search is specific enough to find exactly the right ticket.
Action 3: Stop
- Click Add New Action, select Stop Processing This Message Completely, click OK
- Name it
Stop - Set Only perform this action if:
custom.device_nameis not empty
If the device name extraction returns empty (for example, the email format is unexpected), steps 2 and 3 are skipped. The email is not stopped, so any catch-all rule further down the mailbox's rule list will fire instead. This lets you handle unknown alert formats separately rather than silently discarding them.
Rule 2: Process Online Alerts
This rule fires when a device reconnects, finds the original offline ticket, adds a note, and closes it.
Clone Rule 1 to use it as a starting point, then make the following changes.
Add the rule
- Clone Rule 1 or create a new rule named
Process UniFi Online Alerts - Change the Expression to: subject equals
Device Reconnected - Delete the Create Ticket and Stop actions, keeping only the Extract Device Name step
Action 1: Extract the device name (same as Rule 1)
Keep the same extraction step: {{after_string email.body "Device Name: " flags="tn"}} stored as device_name.
Action 2: Query Autotask for the open offline ticket
- Click Add New Action, select API: Query for One Object, click OK
- Name the step
Find Open Offline Ticket - Set Entity Type to
Ticket - Set Only perform this action if:
custom.device_nameis not empty - Add query conditions:
Statusdoes not equalCompleteDescriptioncontains[UniFi Device: {{custom.device_name}}]
- Set Sort to
CreateDatedescending - Leave Generate exception if no results unchecked (it is valid for an online alert to arrive with no matching open ticket)
- In Store results in variable, enter
ticket
Action 3: Update the ticket status to Complete
- Click Add New Action, select API: Update an Object, click OK
- Name the step
Close Ticket - Set Entity Type to
Ticket - Set Only perform this action if:
custom.ticket.idis not empty - Configure fields (only add the fields you want to change):
| Field | Value |
|---|---|
| ID | {{custom.ticket.id}} (unlock the field) |
| Status | Complete |
Action 4: Add a note to the ticket
- Click Add New Action, select API: Create an Object, click OK
- Name the step
Add Reconnection Note - Set Entity Type to
TicketNote - Set Only perform this action if:
custom.ticket.idis not empty - Configure fields:
| Field | Value |
|---|---|
| TicketID | {{custom.ticket.id}} (unlock the field) |
| Title | {{email.subject}} |
| Description | {{email.body}} |
| NoteType | Task Summary |
| Publish | All Autotask Users |
In the Autotask UI, adding a note and changing status look like one step. The API requires two separate calls. Order them as: update status first, then create the note.
Action 5: Stop
- Click Add New Action, select Stop Processing This Message Completely, click OK
- Name it
Stop - Set Only perform this action if:
custom.ticket.idis not empty
When custom.ticket.id is empty (no open ticket was found for the device), the stop is skipped. A catch-all rule can then handle the unmatched online alert.
Rule Order
Drag the rules into this order in the mailbox and save the order:
Process UniFi Offline Alerts(expression: subject equalsDevice Offline)Process UniFi Online Alerts(expression: subject equalsDevice Reconnected)- A catch-all rule with no expression (optional, recommended): handles any UniFi email that did not match the above two rules
Each rule has an expression, so only one rule fires per email. The catch-all at the bottom fires only if neither of the first two rules stopped the message.
Test the Workflow
Test the offline alert:
- Replay the offline email from History (or send a new one)
- Open the processing log and verify:
- The device name was extracted correctly
- A ticket was created in Autotask with the
[UniFi Device: ...]tag in the description
- Open the ticket in Autotask to confirm the description and title look correct
Test the online alert:
- Replay the online email from History (or send a new one)
- Open the processing log and verify:
- The device name was extracted correctly
- Autotask was queried and the correct open ticket was found
- The ticket status was changed to Complete
- A note was added to the ticket
The Play button on any History entry re-processes the same email through your current rules. You do not need to send new test emails each time you adjust a rule.
Part 2: Associate Tickets to the Correct Account
By default, Part 1 creates every ticket on your zero account. If each of your customers has their own UniFi controller sending alerts from a customer-specific email address (for example, [email protected]), you can use that from address to look up the correct Autotask account and create the ticket there instead.
How It Works
When an offline alert arrives:
- Extract the device name (same as before)
- Query Autotask for a Contact whose email address matches the alert's from address
- If a matching Contact is found: create the ticket on that Contact's account and optionally associate the Contact
- If no matching Contact is found: fall back to creating the ticket on the zero account
Setting Up Account Association
Clone your offline alert rule and add a Contact lookup step between extraction and ticket creation. Disable the original rule once the new one is ready.
Action 2: Query Autotask for the contact
- Click Add New Action, select API: Query for One Object, click OK
- Name the step
Query Autotask for Contact - Set Entity Type to
Contact - Set Only perform this action if:
custom.device_nameis not empty - Add query conditions (use an OR group for all three):
Activeequals1- OR group:
EmailAddressequals{{email.from.address}}EmailAddress2equals{{email.from.address}}EmailAddress3equals{{email.from.address}}
- Leave Generate exception if no results unchecked (no contact found is a valid fallback)
- In Store results in variable, enter
contact
Action 3: Create ticket (contact found)
- Clone the existing Create Ticket step to get two versions
- Name this one
Create Ticket (Contact Found) - Set Only perform this action if:
custom.contact.idis not empty - Unlock both AccountID and ContactID fields:
- AccountID:
{{custom.contact.accountId}}(the account the contact belongs to) - ContactID:
{{custom.contact.id}}(optional: associates the contact to the ticket)
- AccountID:
Action 4: Create ticket (no contact found)
- Name this version
Create Ticket (No Contact) - Set Only perform this action if:
custom.contact.idis empty - Set AccountID back to
0(the zero account) and remove the ContactID field
Action 5: Stop
Keep the same stop step, still conditioned on custom.device_name is not empty.
Alternative Approaches
The Contact lookup is the most common approach, but it is not the only one. You can query for any Autotask entity that stores the UniFi controller's email address:
- Account User-Defined Field: add a UDF to the Account called
UniFi Alert Addressand query Accounts where that UDF equals{{email.from.address}} - Configuration Item: store the controller's email address on a CI and query InstalledProducts
- Custom mapping: use a Render Text step to hard-code account IDs for known from addresses
The query in step 2 is the only thing that changes between these approaches. Everything else stays the same.
Online Alert: Optional Account Filtering
For most setups, the online alert rule does not need account-aware logic. The device name tag in the ticket description is specific enough to find the right ticket regardless of which account it is on.
If you have multiple customers with devices that share the same name (for example, AP-01 at every site), add an additional filter to the ticket query:
- Query for Contact (same OR group as above), store as
contact - In the Find Open Offline Ticket query, add:
AccountIDequals{{custom.contact.accountId}}
This ensures the ticket found belongs to the same account as the alert's sender.
Key Takeaways
- One mailbox for UniFi alerts: keep these rules isolated from your general support mailbox
- The device name tag links the two emails: embedding
[UniFi Device: name]in the ticket description is what allows the online alert to find and close the correct ticket - Guard every action with a condition: if the device name or ticket lookup returns empty, skipping dependent steps allows a catch-all rule to handle the edge case gracefully
- Two API calls to add a note and change status: Autotask requires separate calls; update the ticket status first, then create the TicketNote
- History is your best debugging tool: use Replay and the processing log to see exactly what was extracted and what Autotask returned at each step
What's Next
- Core Concepts: understand the mailbox/rule/action hierarchy
- Monitoring Alerts Tutorial: a generalised version of this pattern for any monitoring tool
- Extract Strings: the newer action for extracting structured data from email text
- API: Query for One Object: querying Autotask for a single result
- API: Create an Object: creating any Autotask entity
- API: Update an Object: updating any Autotask entity