Skip to content

Commit

Permalink
Add email support
Browse files Browse the repository at this point in the history
  • Loading branch information
GladOSkar committed Feb 19, 2025
1 parent 5dd56ff commit 3de3676
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions join.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import http.server as server
from urllib.parse import parse_qs

from smtplib import SMTP

CSVFILE = "applicants.csv"

COLS = [
Expand All @@ -24,6 +26,35 @@
"inhaber"
]

def send_notif(data):
try:
conn = SMTP('smtp.office365.com', 587)
conn.ehlo()
r = conn.starttls()
if r[0] != 220:
print("No Starttls!")
return
print("STARTTLS enabled")
try:
conn.login('noreply@fasttube.de', os.environ.get('FTFV_SMTP_PW'))
conn.sendmail('fv@fasttube.de', 'fv@fasttube.de', ("""\
From: Förderverein FaSTTUBe e.V. <fv@fasttube.de>
To: Förderverein FaSTTUBe e.V. Verteiler <fv@fasttube.de>
Subject: Neuer Aufnahmeantrag über das Beitrittsformular!
Eine neue Anmeldung kann vom Server abgerufen werden. Daten:
%s
Bitte den Aufnahmeprozess starten.
""" % "\n".join(data)).encode('utf-8'))
finally:
conn.quit()
print("Mail sent.")
except Exception as e:
print("Error while sending email:", e)
return

class HTTPRequestHandler(server.SimpleHTTPRequestHandler):

def do_POST(self):
Expand All @@ -47,6 +78,8 @@ def do_POST(self):
writer = csv.writer(f)
writer.writerow([data.get(c, [now_iso])[0] for c in COLS])

send_notif([f"{c}: {data.get(c, [now_iso])[0]}" for c in COLS])

self.send_response(201, 'Created')
self.end_headers()
self.wfile.write("""<!DOCTYPE html>
Expand Down

0 comments on commit 3de3676

Please sign in to comment.