mirror of
https://github.com/draga79/NotiMail.git
synced 2024-11-12 16:51:34 +01:00
Added Pushover support and documentation fixes
This commit is contained in:
parent
53afd78c99
commit
e1b9e9ecc1
3 changed files with 45 additions and 7 deletions
33
NotiMail.py
33
NotiMail.py
|
@ -1,6 +1,6 @@
|
|||
"""
|
||||
NotiMail
|
||||
Version: 0.8
|
||||
Version: 0.8 - Alpha
|
||||
Author: Stefano Marinelli <stefano@dragas.it>
|
||||
License: BSD 3-Clause License
|
||||
|
||||
|
@ -171,6 +171,32 @@ class NTFYNotificationProvider(NotificationProvider):
|
|||
finally:
|
||||
time.sleep(5) # Ensure a delay between notifications
|
||||
|
||||
class PushoverNotificationProvider(NotificationProvider):
|
||||
def __init__(self, api_token, user_key):
|
||||
self.api_token = api_token
|
||||
self.user_key = user_key
|
||||
self.pushover_url = "https://api.pushover.net/1/messages.json"
|
||||
|
||||
def send_notification(self, mail_from, mail_subject):
|
||||
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"From: {mail_from}\nSubject: {mail_subject}"
|
||||
|
||||
data = {
|
||||
"token": self.api_token,
|
||||
"user": self.user_key,
|
||||
"message": message
|
||||
}
|
||||
|
||||
try:
|
||||
response = requests.post(self.pushover_url, data=data)
|
||||
if response.status_code == 200:
|
||||
print("Notification sent successfully via Pushover!")
|
||||
else:
|
||||
print(f"Failed to send notification via Pushover. Status Code:", response.status_code)
|
||||
except requests.RequestException as e:
|
||||
print(f"An error occurred while sending notification via Pushover: {str(e)}")
|
||||
|
||||
class Notifier:
|
||||
def __init__(self, providers):
|
||||
|
@ -246,6 +272,11 @@ if 'NTFY' in config:
|
|||
ntfy_urls = [config['NTFY'][url_key] for url_key in config['NTFY']]
|
||||
providers.append(NTFYNotificationProvider(ntfy_urls))
|
||||
|
||||
if 'PUSHOVER' in config:
|
||||
api_token = config['PUSHOVER']['ApiToken']
|
||||
user_key = config['PUSHOVER']['UserKey']
|
||||
providers.append(PushoverNotificationProvider(api_token, user_key))
|
||||
|
||||
# Initialize Notifier with providers
|
||||
notifier = Notifier(providers)
|
||||
|
||||
|
|
12
README.md
12
README.md
|
@ -2,7 +2,7 @@
|
|||
|
||||
**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 using the renowned `ntfy` service!
|
||||
Stay connected without the constant drain on your battery. Introducing **NotiMail** - the future of server-side email notifications supporting multiple push providers!
|
||||
|
||||
Mobile devices often use IMAP IDLE, maintaining a persistent connection to ensure real-time email notifications. Such continuous connections rapidly consume battery power. The modern era demanded a smarter, more energy-efficient solution. Meet NotiMail.
|
||||
|
||||
|
@ -12,22 +12,24 @@ Mobile devices often use IMAP IDLE, maintaining a persistent connection to ensur
|
|||
|
||||
- **Processes and Notifies**: Once a new email is detected, NotiMail swiftly processes its details.
|
||||
|
||||
- **Leverages 'ntfy' for Alerts**: Rather than having your device always on alert, NotiMail sends notifications via the `ntfy` service, 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.
|
||||
|
||||
- **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.
|
||||
|
||||
- **Multiple And Different Push providers supported**: You can use one or more of the supported Push providers, which currently include ntfy and Pushover.
|
||||
|
||||
|
||||
## Benefits 🚀
|
||||
|
||||
- **Extended Battery Life**: Experience a noticeable improvement in your device's battery lifespan.
|
||||
|
||||
- **Swift Notifications**: With the `ntfy` service, NotiMail provides real-time notifications without delay.
|
||||
- **Swift Notifications**: Using one of the supported push providers, NotiMail provides real-time notifications without delay.
|
||||
|
||||
- **Reduced Data Consumption**: With notifications being the primary data exchange, you can save on unnecessary data usage.
|
||||
|
||||
- **Always in the Loop**: Whether it's a new email or a server glitch, NotiMail and `ntfy` guarantee you're always informed.
|
||||
- **Always in the Loop**: Whether it's a new email or a server glitch, NotiMail and push notifications guarantee you're always informed.
|
||||
|
||||
|
||||
## Implementation Details 🔧
|
||||
|
@ -109,7 +111,7 @@ bash
|
|||
|
||||
**5. Configure NotiMail:**
|
||||
|
||||
Open the `config.ini` file in a text editor. Update the `[EMAIL]` section with your email credentials and host, and the `[NTFY]` section with the appropriate `NtfyURL`. For more information about ntfy and its configuration, please read the [official website](https://docs.ntfy.sh/)
|
||||
Open the `config.ini` file in a text editor. Update the `[EMAIL]` section with your email credentials and host, and the configuration of one (or more) of the supported push providers.
|
||||
|
||||
**6. Run NotiMail:**
|
||||
|
||||
|
|
|
@ -3,8 +3,13 @@ EmailUser = your@address.com
|
|||
EmailPass = YourPassword
|
||||
Host = mail.server.com
|
||||
|
||||
#If your provider is NTFY, uncomment the following lines
|
||||
#If your provider is NTFY, uncomment the following lines and configure
|
||||
#[NTFY]
|
||||
#Url1 = https://ntfy.sh/TOPIC1
|
||||
#Url2 = https://ntfy.sh/TOPIC2
|
||||
|
||||
#If your provider is PUSHOVER, uncomment the following lines and configure
|
||||
#[PUSHOVER]
|
||||
#ApiToken = YOUR_PUSHOVER_API_TOKEN
|
||||
#UserKey = YOUR_PUSHOVER_USER_KEY
|
||||
|
||||
|
|
Loading…
Reference in a new issue