diff options
author | Runxi Yu <me@runxiyu.org> | 2024-05-11 22:23:50 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2024-05-11 22:23:50 +0800 |
commit | e7f64212afb97f490c49a828a345dbea5ca34970 (patch) | |
tree | 0dfff9848a7f268187bf17b0982ae94b17707a50 | |
parent | 337cdb29b6082b92fb21470cbe4fcc495f49ae94 (diff) | |
download | www-e7f64212afb97f490c49a828a345dbea5ca34970.tar.gz |
hybrid.cgi: Send email
-rwxr-xr-x | hybrid.cgi | 10 |
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) |