gmailalert is a Go package and command-line app that scans a Gmail user's account for emails matching specified patterns and emits Pushover alerts when matches are found.
- Install the gmailalert command-line app by running
go install https://github.com/elskohder/gmailalert/cmd/gmailalert@latest
- You will need to create a Google Cloud Project with the API enabled.
- You will need to create access credentials for a Google desktop application and download them to your local machine. These are typically saved in a file called
credentials.json
. - You will need to have a Pushover account with at least one application configured in it. See the Pushover support page for more help setting up a Pushover application.
$ ./gmailalert -h
Usage of gmailalert:
-alerts-cfg-file string
json file containing the alerting criteria (default "alerts.json")
-credentials-file string
json file containing your Google Developers Console credentials (default "credentials.json")
-debug
enable debug-level-logging
-port int
the port for the local http server to listen on for redirects from the Gmail OAuth2 resource provider (default 9999)
-token-file string
json file to read your Gmail OAuth2 token from (if present), or to save your Gmail OAuth2 token into (if not present) (default "token.json")
The gmailalert app reads a JSON configuration file containing email matching criteria (in Gmail query format) and the corresponding Pushover message to send when matches occur. This JSON configuration file is specified with the -alerts-cfg
flag in the gmailalert command-line app.
Here is an example configuration:
{
"pushoverapp": "NOT SHOWN HERE",
"alerts": [
{
"gmailquery": "is:unread subject:Your Bill is Available Online",
"pushovertarget": "NOT SHOWN HERE",
"pushovertitle": "Bill Due!",
"pushoversound": "cashregister"
},
{
"gmailquery": "is:unread subject:Your zoom meeting has started",
"pushovertarget": "NOT SHOWN HERE",
"pushovertitle": "Zoom Meeting Started!",
"pushoversound": "siren"
}
]
}
Some points to note here:
- The value of the "pushoverapp" field is the API token for the pushover application that you want to emit notifications with.
- The value of the "pushovertarget" field is your Pushover account user key.
For example, assuming the JSON configuration shown above is saved in a file called alerts.json
:
$ ./gmailalert -alerts-cfg-file alerts.json
INFO: 2022/08/17 22:31:21 Found 0 emails matching query "is:unread subject:Your zoom meeting has started"
INFO: 2022/08/17 22:31:21 Found 1 emails matching query "is:unread subject:Your Bill is Available Online"
INFO: 2022/08/17 22:31:21 notification titled "Bill Due!" successfully sent via gmailalert.PushoverClient