mirror of
https://github.com/FAUSheppy/atlantis-event-dispatcher
synced 2025-12-06 14:31:35 +01:00
add: debug & smtp
This commit is contained in:
@@ -5,13 +5,26 @@ import subprocess
|
|||||||
import os
|
import os
|
||||||
import requests
|
import requests
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
import smtphelper
|
||||||
|
|
||||||
HTTP_NOT_FOUND = 404
|
HTTP_NOT_FOUND = 404
|
||||||
AUTH = None
|
AUTH = None
|
||||||
|
|
||||||
def email_address(dispatch_uuid, user_topic, message, smtp_target, smtp_user, smtp_pass):
|
def debug_send(uuid, data, fail_it=False):
|
||||||
|
'''Dummy function to print and ack a dispatch for debugging'''
|
||||||
|
|
||||||
|
print(json.dumps(data, intent=2))
|
||||||
|
if fail_it:
|
||||||
|
report_failed_dispatch(uuid, "Dummy Error for Debugging")
|
||||||
|
else:
|
||||||
|
confirm_dispatch(uuid)
|
||||||
|
|
||||||
|
|
||||||
|
def email_send(dispatch_uuid, email_address, message, smtp_target, smtp_user, smtp_pass):
|
||||||
'''Send message via email'''
|
'''Send message via email'''
|
||||||
|
|
||||||
|
subject = "Atlantis Dispatch"
|
||||||
|
smtphelper.smtp_send(smtp_target, smtp_user, smtp_pass, email_address, subject, message)
|
||||||
report_failed_dispatch(uuid, "Email dispatch not yet implemented")
|
report_failed_dispatch(uuid, "Email dispatch not yet implemented")
|
||||||
|
|
||||||
def ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, ntfy_pass):
|
def ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, ntfy_pass):
|
||||||
@@ -117,7 +130,11 @@ if __name__ == "__main__":
|
|||||||
elif method == "ntfy":
|
elif method == "ntfy":
|
||||||
ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, ntfy_pass)
|
ntfy_send(dispatch_uuid, user_topic, message, ntfy_push_target, ntfy_user, ntfy_pass)
|
||||||
elif method == "email":
|
elif method == "email":
|
||||||
email_send(email_address, message)
|
email_send(dispatch_uuid, email_address, message, smtp_target, smtp_user, smtp_pass)
|
||||||
|
elif method == "debug":
|
||||||
|
debug_send(uuid, entry)
|
||||||
|
elif method == "debug-fail":
|
||||||
|
debug_send(uuid, entry, fail_it=True)
|
||||||
else:
|
else:
|
||||||
print("Unsupported dispatch method {}".format(entry["method"]), sys=sys.stderr)
|
print("Unsupported dispatch method {}".format(entry["method"]), sys=sys.stderr)
|
||||||
continue
|
continue
|
||||||
|
|||||||
37
client/smtp.py
Normal file
37
client/smtp.py
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
import smtplib
|
||||||
|
from email.mime.text import MIMEText
|
||||||
|
from email.mime.multipart import MIMEMultipart
|
||||||
|
|
||||||
|
def smtp_send(server, user, password, recipient, subject, body):
|
||||||
|
|
||||||
|
# Email and password for authentication
|
||||||
|
sender_email = f'{user}@{server}'
|
||||||
|
sender_password = password
|
||||||
|
|
||||||
|
# Recipient email address
|
||||||
|
recipient_email = recipient
|
||||||
|
|
||||||
|
# SMTP server details
|
||||||
|
smtp_server = server
|
||||||
|
smtp_port = 587 # Default port for TLS connection
|
||||||
|
|
||||||
|
# Create a message
|
||||||
|
message = MIMEMultipart()
|
||||||
|
message['From'] = sender_email
|
||||||
|
message['To'] = recipient_email
|
||||||
|
message['Subject'] = subject
|
||||||
|
|
||||||
|
# Add body to email
|
||||||
|
body = body
|
||||||
|
message.attach(MIMEText(body, 'plain'))
|
||||||
|
|
||||||
|
# Establish a connection to the SMTP server
|
||||||
|
server = smtplib.SMTP(smtp_server, smtp_port)
|
||||||
|
server.starttls() # Secure the connection
|
||||||
|
server.login(sender_email, sender_password)
|
||||||
|
|
||||||
|
# Send the email
|
||||||
|
server.sendmail(sender_email, recipient_email, message.as_string())
|
||||||
|
|
||||||
|
# Close the connection
|
||||||
|
server.quit()
|
||||||
Reference in New Issue
Block a user