diff --git a/NotiMail.py b/NotiMail.py index 2bbd170..72097cc 100644 --- a/NotiMail.py +++ b/NotiMail.py @@ -198,6 +198,37 @@ class PushoverNotificationProvider(NotificationProvider): except requests.RequestException as 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: def __init__(self, providers): self.providers = providers @@ -277,6 +308,11 @@ if 'PUSHOVER' in config: user_key = config['PUSHOVER']['UserKey'] 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 notifier = Notifier(providers) diff --git a/README.md b/README.md index 24ff5be..b622eaa 100644 --- a/README.md +++ b/README.md @@ -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. -- **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 🚀 diff --git a/config.ini b/config.ini index 55de23d..acc4df5 100644 --- a/config.ini +++ b/config.ini @@ -13,3 +13,8 @@ Host = mail.server.com #ApiToken = YOUR_PUSHOVER_API_TOKEN #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 +