Added Apprise support - tons of notification providers are now supported!

This commit is contained in:
Stefano Marinelli 2023-11-07 09:56:29 +01:00
parent eef362f907
commit 6765287e70
4 changed files with 53 additions and 5 deletions

View file

@ -1,3 +1,20 @@
### Version 0.13
#### New Features:
- **Apprise Notification Support**: Introduced the `AppriseNotificationProvider` to allow for notifications through a variety of services via the Apprise library.
#### Changes:
- Added an import statement for the `apprise` library to the script to facilitate the new notification method.
- Updated the `multi_account_main` function to read Apprise configuration from `config.ini` and initialize the `AppriseNotificationProvider`.
- The notification dispatch process within the script now includes the capability to use Apprise, broadening the range of supported notification services.
#### Upgrade Notes:
- To use Apprise, ensure that the `apprise` package is installed (`pip install apprise`).
- Update the `config.ini` file to include a new section `[APPRISE]` with the required service URLs for notifications.
### Version 0.12.1 ### Version 0.12.1
#### Changes: #### Changes:

View file

@ -1,7 +1,7 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
""" """
NotiMail NotiMail
Version: 0.12.1 Version: 0.13
Author: Stefano Marinelli <stefano@dragas.it> Author: Stefano Marinelli <stefano@dragas.it>
License: BSD 3-Clause License License: BSD 3-Clause License
@ -27,6 +27,7 @@ Python Dependencies:
- signal, sys: For handling script shutdown and signals. - signal, sys: For handling script shutdown and signals.
- threading: to deal with multiple inboxes - threading: to deal with multiple inboxes
- BytesParser from email.parser: For parsing raw email data. - BytesParser from email.parser: For parsing raw email data.
- apprise: for apprise notifications
Configuration: Configuration:
The script reads configuration data from a file named config.ini. Ensure it is properly The script reads configuration data from a file named config.ini. Ensure it is properly
@ -74,6 +75,7 @@ import sys
import logging import logging
import argparse import argparse
import threading import threading
import apprise
from email import policy from email import policy
from email.parser import BytesParser from email.parser import BytesParser
@ -184,6 +186,27 @@ class NotificationProvider:
def send_notification(self, mail_from, mail_subject): def send_notification(self, mail_from, mail_subject):
raise NotImplementedError("Subclasses must implement this method") raise NotImplementedError("Subclasses must implement this method")
class AppriseNotificationProvider(NotificationProvider):
def __init__(self, apprise_config):
# Initialize the apprise object
self.apprise = apprise.Apprise()
# Add all the services by the configuration provided
for service_url in apprise_config:
self.apprise.add(service_url)
def send_notification(self, mail_from, mail_subject):
# Prepare the notification message
mail_subject = mail_subject if mail_subject is not None else "No Subject"
mail_from = mail_from if mail_from is not None else "Unknown Sender"
message = f"{mail_from}"
# Send the notification
if not self.apprise.notify(title=mail_subject, body=message):
# If notification fails, log the failure
logging.error(f"Failed to send notification via Apprise.")
print(f"Failed to send notification via Apprise.")
class NTFYNotificationProvider(NotificationProvider): class NTFYNotificationProvider(NotificationProvider):
def __init__(self, ntfy_data): def __init__(self, ntfy_data):
#self.ntfy_urls = ntfy_urls # Expecting a list of URLs #self.ntfy_urls = ntfy_urls # Expecting a list of URLs
@ -427,6 +450,11 @@ def multi_account_main():
providers = [] providers = []
if 'APPRISE' in config:
apprise_urls = config['APPRISE']['urls'].split(',') # Assuming urls is a comma-separated list in the config
providers.append(AppriseNotificationProvider(apprise_urls))
if 'NTFY' in config: if 'NTFY' in config:
ntfy_data = [] ntfy_data = []
for key in config['NTFY']: for key in config['NTFY']:

View file

@ -1,8 +1,6 @@
# NotiMail 📧 # NotiMail 📧
**Version 0.12.1 is here, read the changelog for more information!** **Version 0.13 is here, read the changelog for more information!**
**Development is ongoing, and the project is in the early alpha stage - things may break!**
Stay connected without the constant drain on your battery. Introducing **NotiMail** - the future of server-side email notifications supporting multiple push providers and multiple email accounts! Stay connected without the constant drain on your battery. Introducing **NotiMail** - the future of server-side email notifications supporting multiple push providers and multiple email accounts!
@ -18,11 +16,13 @@ Mobile devices often use IMAP IDLE, maintaining a persistent connection to ensur
- **Leverages Multiple Push Providers for Alerts**: Rather than having your device always on alert, NotiMail sends notifications via multiple push providers, ensuring you're promptly informed. - **Leverages Multiple Push Providers for Alerts**: Rather than having your device always on alert, NotiMail sends notifications via multiple push providers, ensuring you're promptly informed.
- **Expanded Notification Capabilities**: Version 0.13 introduces support for Apprise, allowing for an extensive array of notification services through a single interface.
- **Database Integration**: NotiMail uses an SQLite3 database to store and manage processed email UIDs, preventing repeated processing. - **Database Integration**: NotiMail uses an SQLite3 database to store and manage processed email UIDs, preventing repeated processing.
- **Built for Resilience**: With connectivity hiccups in mind, NotiMail ensures you're always the first to know. - **Built for Resilience**: With connectivity hiccups in mind, NotiMail ensures you're always the first to know.
- **Multiple And Different Push providers supported**: You can use one or more of the supported Push providers - all support authentication, which currently include ntfy, Gotify, and Pushover. - **Multiple And Different Push providers supported**: You can use one or more of the supported Push providers - all support authentication, which now includes ntfy, Gotify, Pushover, and a wide range through Apprise.
## Benefits 🚀 ## Benefits 🚀

View file

@ -31,3 +31,6 @@ Host = mail.server.com
#Url = https://gotify.example.com/message #Url = https://gotify.example.com/message
#Token = your_gotify_token #Token = your_gotify_token
#If your provider is one of the ones supported by APPRISE, uncomment the following lines and configure. If using APPRISE, also uncomment the [APPRISE] line
#[APPRISE]
#urls = pover://user@token, discord://webhook_id/webhook_token