summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorRunxi Yu <me@runxiyu.org>2024-05-11 22:23:50 +0800
committerRunxi Yu <me@runxiyu.org>2024-05-11 22:23:50 +0800
commite7f64212afb97f490c49a828a345dbea5ca34970 (patch)
tree0dfff9848a7f268187bf17b0982ae94b17707a50
parent337cdb29b6082b92fb21470cbe4fcc495f49ae94 (diff)
downloadwww-e7f64212afb97f490c49a828a345dbea5ca34970.tar.gz
hybrid.cgi: Send email
-rwxr-xr-xhybrid.cgi10
1 files changed, 9 insertions, 1 deletions
diff --git a/hybrid.cgi b/hybrid.cgi
index 8323450..1c9afda 100755
--- a/hybrid.cgi
+++ b/hybrid.cgi
@@ -7,6 +7,7 @@ import os
 import cgi
 import pathlib
 import shutil
+import smtplib
 
 FBDIR="/srv/fb"
 
@@ -90,7 +91,14 @@ def fbw() -> None:
     sys.stdout.write("\r\n")
     fn = os.path.basename(file.filename)
     open(os.path.join(FBDIR, fn), 'wb').write(file.file.read())
-    sys.stdout.write("Done.")
+    msg = """Subject: New file upload\r\nTo: me@runxiyu.org\r\nFrom: www-data@runxiyu.org\r\n\r\nA new file upload is available at:\n\n%s""" % os.path.join(FBDIR, fn)
+    try:
+        server = smtplib.SMTP("localhost")
+        server.sendmail("www-data@runxiyu.org", ["me@runxiyu.org"], msg)
+        server.quit()
+    except Exception:
+        sys.stdout.write("WARNING: Email error. Email not sent.\n")
+    sys.stdout.write("Done uploading.")
     exit(0)