Home Assistant is a great centralized resource to connect all of your home smart devices, yet it's great on a software front, too. One integration that I find often gets overlooked is the built-in IMAP integration, a way to link Home Assistant to your email and react accordingly to incoming messages. It's a very basic way to turn your email into an API, and you can automate responses to specific events or triggers.
Setting up the IMAP integration is easy and can be done from the Home Assistant UI. If you have two-factor authentication enabled on Gmail, you'll need to use an "app password" to log in from Home Assistant, which the integration will provide instructions for installing. Once set up, you're ready to go.
Processing emails to look for triggers
Setting up our integration

Firstly, we'll need to make sure the IMAP integration can see all of the details of each email and its contents. Go to the IMAP integration in Home Assistant, then click Configure beside your email. Enable both Body text and Message headers, as this will allow you to process all of the information from a received email and use it for triggering specific events.
Right now, every time an email is received, an "imap_content" event is triggered. This is a transient event containing the information of the most recent email, divided into the following fields of data:
- subject
- entry_id
- uid
- text
- server
- username
- search
- folder
- sender
- date
- subject
- initial
- Delivered-To header
- Return-Path header
- Received header
- Received-last header
Most of these details likely aren't too important for triggering automations, but the "sender", "subject", and "text" are what we'll be tapping into. These transient events carry these pieces of information, and you can do a lot. For example, when a bill comes in, you can pull the information from the bill and process it, passing it through Home Assistant and pulling the values associated with the bill to another sensor. We'll first build an automation to announce a package delivery over a speaker.
Announcing a package delivery using Home Assistant's IMAP
Never miss a package delivery again

So, with many delivery services, you'll probably get an email telling you when a package has been delivered. I'm not always looking at my email, and when I'm on my PC, I won't actually see an email for a while once I've received it. Most of the time, couriers will call me when a package is on the way, but sometimes, they just leave my package downstairs in my apartment lobby. To deal with the issue, I've deployed this setup:
- Email comes in, triggering the imap_content event
- Scan the subject of the email by converting it to lowercase and checking if it contains "delivered"
- If it's a match, announce the delivery of the package over my living room media player, using everything before the @ in the email address as the name of the sender
We use the "initial: true" flag in the imap_content event so that we only trigger on totally new emails. Once an email comes in, we check if it matches our template as a condition to continue. Finally, I use TTS to play an announcement on my speaker, where it splits the email sender based on the @.
"Your {{ trigger.event.data.sender.split('@')[0] }} parcel has arrived."If we used adam@xda-developers.com as an example, this would split my email address into an array of two items: ["adam", "xda-developers.com"]. Referencing position [0] means reading just "adam", and abstracting that concept and applying it to other email addresses means that you can pull the first half of the email of the sender. It doesn't have to just be packages; you could configure this to notify you if someone specifically emails you.
In hindsight, it would likely be better to pull the second half of the email address by referencing [1] instead. This is because many sender email addresses might not be too descriptive. For example, in Ireland, my Amazon delivery notifications come from "auto-confirm@amazon.co.uk". It would make more sense to reference [1] for the announcement, so that it says "Your Amazon.co.uk parcel has arrived". I simply hadn't gotten around to changing it until now, but using [0] may still better suit your needs in some scenarios.
Tracking bills with Home Assistant's IMAP
Saving them to sensors

Another great use for the IMAP integration is to track bills, and for this, we'll use a template sensor instead that will keep track of bills received from a particular sender. This can be expanded to use multiple attributes for different bills, or you could use different sensors entirely. This could also be advanced to have a tally of all of the bills collected for the month, though this demonstration is just to show how you can implement IMAP as part of a template rather than being the basis of an automation. This allows for static data to be saved in a template that can be referenced in the future.
For this, I'm going to read my incoming emails to check for a new bill from my mobile provider. The emails contain two price values: the first is always the bill amount, the second is the late penalty fee if the payment is missed. Therefore, we want to always pull the first value and not the second. As well, while I haven't done it here for the purposes of testing (as I'm emailing myself a copy of the bill email for testing), you would also want to limit the sender parameters to be just from the provider you want to check for. However, my template to get the above result looks like this:
- trigger:- trigger: event
event_type: "imap_content"
id: "bills"
sensor:
- name: bills
icon: mdi:receipt
state: >
{%- set val = trigger.event.data.text
| regex_findall_index('\d+\.\d+', 0) %}
{{ val | float(0) }}
attributes:
gomo_bill: >
{%- set val = trigger.event.data.text
| regex_findall_index('\d+\.\d+', 0) %}
{{ val | float(0) }}
This is a simple template that checks if an update to the value is needed based on a received email. It looks for a value in the form of [decimal].[decimal], and takes the first instance of it. Then, it converts it to a float and saves it to the state. This same logic is used for the attribute as well. You can expand this in the future to look for specific senders and to sort it based on the sender, and you can also use the current state as the most recently processed value.
However, if you wanted, you could also create separate sensors for these, so you could have bills_electricity, bills_broadband, etc. It's whatever way works for you, but you can control it and how you save it.
Email is still important

IMAP is one of the greatest and most underutilized tools in the entire smart home ecosystem. Just 1522 active installations use it according to Home Assistant's own metrics (at the time of writing, anyway), which pales in comparison to even number 30 having over 67,000 installations. It's flown under the radar, largely in part thanks to the stellar integrations that the community has built to support all kinds of services. Still, plenty of tools only operate via email, and you can automate anything you want in the same way that you would automate anything else in Home Assistant, though with email as the trigger.
If you have any services that send important emails that you'd like to track, this can be a very useful tool. For bills, it's already fantastic, and I'm in the process of growing out some of my invoice tracking and other tools through it as well. It can rival many tools that can monitor your email in the same way, or you could use it as a way to control your home and share access with family members by sending emails. Plus, you could configure the SMTP integration for automated responses, too. Home Assistant's documentation even has a great example of using notifications from a UPS to tell whether your home's power is out, so let your imagination run wild.