NotiMail - Monitor email inbox(es) and send notifications upon new
email arrivals using various providers.
notimail [-c CONFIG] [--print-config]
[--test-config] [--list-folders]
NotiMail is a script designed to monitor one or more email inboxes
using the IMAP IDLE feature. It automatically processes new emails and sends
notifications (including sender and subject) to various push notification
providers. It supports multiple email accounts and folders, ensuring that
emails are not processed repeatedly by using an SQLite database.
In addition, NotiMail now includes:
- A web interface (via Flask) to display status, logs, and
configuration.
- Prometheus metrics export for detailed monitoring (emails processed,
notifications sent, processing time, errors).
- Dynamic configuration reload via SIGHUP (without restarting the
service).
- Robust startup checks with errors printed both to stdout and to the
log.
- -c, --config
CONFIG
- Specify the path to the configuration file. Defaults to
config.ini.
- --print-config
- Print the current configuration from the config.ini file.
- --test-config
- Test the configuration settings, including connectivity and notification
providers.
- --list-folders
- List all the IMAP folders of the configured mailboxes.
Configuration is read from a file named config.ini. Ensure
it is correctly set up before running NotiMail. The configuration file
consists of multiple sections:
- [GENERAL]:
- Specifies general settings:
- LogFileLocation:
- Path to the log file.
- DataBaseLocation:
- Path to the SQLite3 database for storing processed emails.
- LogRotationType:
- Type of log rotation (size or time).
- LogRotationSize:
- Size threshold for log rotation (used if LogRotationType is
size).
- LogRotationInterval:
- Time interval (in days) for log rotation (used if LogRotationType
is time).
- LogBackupCount:
- Number of backup log files to retain.
- PrometheusHost:
- Hostname for the Prometheus metrics server.
- PrometheusPort:
- Port for the Prometheus metrics server.
- FlaskHost:
- Hostname for the Flask web interface.
- FlaskPort:
- Port for the Flask web interface.
- APIKey:
- API key required to access secure web endpoints.
- [EMAIL:accountX]:
- Defines an email account (replace accountX with a unique
identifier).
- EmailUser:
- Email address for the account.
- EmailPass:
- Password for the email account.
- Host:
- IMAP server hostname.
- Folders:
- Comma-separated list of folders to monitor.
- [NTFY]:
- Settings for the NTFY notification provider.
- UrlX:
- NTFY URL for sending notifications (replace X with a unique
number).
- TokenX:
- (Optional) Token for protected topics.
- [PUSHOVER]:
- Settings for the Pushover provider.
- ApiToken:
- Pushover API token.
- UserKey:
- Pushover user key.
- [GOTIFY]:
- Settings for the Gotify provider.
- Url:
- Gotify URL for sending messages.
- Token:
- Gotify token.
- [APPRISE]:
- Settings for the Apprise provider.
- urls:
- Comma-separated list of Apprise service URLs.
NotiMail requires the following Python libraries:
- imaplib
- email
- requests
- configparser
- time, socket
- sqlite3
- datetime
- signal, sys
- logging
- argparse
- threading
- BytesParser (from email.parser)
- apprise (optional, for additional notifications)
- Flask (optional, for the web interface)
- Prometheus Client (optional, for metrics export)
NotiMail runs from the command line and performs initial startup
checks including:
- Testing log file write access.
- Testing database operations.
- Sending a test notification via global providers.
If any startup check fails, an error message is printed to stdout and logged,
and the program exits.
When enabled, the web interface provides:
- /status
- Displays the status of monitored email accounts (requires API key).
- /logs
- Shows the last 100 lines of the log file (requires API key).
- /config
- Returns the current configuration with sensitive values redacted (requires
API key).
Prometheus metrics, if configured, export statistics such as:
NotiMail supports dynamic configuration reload. Sending a SIGHUP
signal to the running process reloads config.ini without restarting
the service:
kill -SIGHUP <process_id>
Additionally, standard signals (SIGTERM, SIGINT) are handled for
graceful shutdown.
1. Running NotiMail with the default configuration:
2. Running NotiMail with a custom configuration file:
-
- notimail -c /path/to/custom_config.ini
3. Printing the current configuration:
4. Testing the configuration settings:
5. Listing the IMAP folders for the configured mailboxes:
Stefano Marinelli <stefano@dragas.it>
BSD 3-Clause License. See the source distribution for details.
IMAP IDLE(3), SQLite3(3), NTFY, Pushover, Gotify, Apprise, Flask,
Prometheus Client.