mirror of
https://github.com/draga79/NotiMail.git
synced 2024-11-09 23:51:07 +01:00
Added Gotify support and documentation fixes
This commit is contained in:
parent
e1b9e9ecc1
commit
a295865987
3 changed files with 42 additions and 1 deletions
36
NotiMail.py
36
NotiMail.py
|
@ -198,6 +198,37 @@ class PushoverNotificationProvider(NotificationProvider):
|
||||||
except requests.RequestException as e:
|
except requests.RequestException as e:
|
||||||
print(f"An error occurred while sending notification via Pushover: {str(e)}")
|
print(f"An error occurred while sending notification via Pushover: {str(e)}")
|
||||||
|
|
||||||
|
class GotifyNotificationProvider(NotificationProvider):
|
||||||
|
def __init__(self, gotify_url, gotify_token):
|
||||||
|
self.gotify_url = gotify_url
|
||||||
|
self.gotify_token = gotify_token
|
||||||
|
|
||||||
|
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}"
|
||||||
|
|
||||||
|
# Include the token in the URL
|
||||||
|
url_with_token = f"{self.gotify_url}?token={self.gotify_token}"
|
||||||
|
|
||||||
|
payload = {
|
||||||
|
"title": mail_subject,
|
||||||
|
"message": message,
|
||||||
|
"priority": 5 # Adjust priority as needed
|
||||||
|
}
|
||||||
|
|
||||||
|
try:
|
||||||
|
response = requests.post(url_with_token, json=payload)
|
||||||
|
if response.status_code == 200:
|
||||||
|
print("Notification sent successfully via Gotify!")
|
||||||
|
else:
|
||||||
|
print(f"Failed to send notification via Gotify. Status Code: {response.status_code}")
|
||||||
|
print(f"Response: {response.text}") # Print the response body
|
||||||
|
except requests.RequestException as e:
|
||||||
|
print(f"An error occurred while sending notification via Gotify: {str(e)}")
|
||||||
|
|
||||||
|
|
||||||
class Notifier:
|
class Notifier:
|
||||||
def __init__(self, providers):
|
def __init__(self, providers):
|
||||||
self.providers = providers
|
self.providers = providers
|
||||||
|
@ -277,6 +308,11 @@ if 'PUSHOVER' in config:
|
||||||
user_key = config['PUSHOVER']['UserKey']
|
user_key = config['PUSHOVER']['UserKey']
|
||||||
providers.append(PushoverNotificationProvider(api_token, user_key))
|
providers.append(PushoverNotificationProvider(api_token, user_key))
|
||||||
|
|
||||||
|
if 'GOTIFY' in config:
|
||||||
|
gotify_url = config['GOTIFY']['Url']
|
||||||
|
gotify_token = config['GOTIFY']['Token']
|
||||||
|
providers.append(GotifyNotificationProvider(gotify_url, gotify_token))
|
||||||
|
|
||||||
# Initialize Notifier with providers
|
# Initialize Notifier with providers
|
||||||
notifier = Notifier(providers)
|
notifier = Notifier(providers)
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ Mobile devices often use IMAP IDLE, maintaining a persistent connection to ensur
|
||||||
|
|
||||||
- **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, which currently include ntfy and Pushover.
|
- **Multiple And Different Push providers supported**: You can use one or more of the supported Push providers, which currently include ntfy, Gotify and Pushover.
|
||||||
|
|
||||||
|
|
||||||
## Benefits 🚀
|
## Benefits 🚀
|
||||||
|
|
|
@ -13,3 +13,8 @@ Host = mail.server.com
|
||||||
#ApiToken = YOUR_PUSHOVER_API_TOKEN
|
#ApiToken = YOUR_PUSHOVER_API_TOKEN
|
||||||
#UserKey = YOUR_PUSHOVER_USER_KEY
|
#UserKey = YOUR_PUSHOVER_USER_KEY
|
||||||
|
|
||||||
|
#If your provider is GOTIFY, uncomment the following lines and configure
|
||||||
|
#[GOTIFY]
|
||||||
|
#Url = https://gotify.example.com/message
|
||||||
|
#Token = your_gotify_token
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue