From dff448f76635d819528e3e4eae59685d5ca6f9c5 Mon Sep 17 00:00:00 2001 From: ryansurf Date: Fri, 24 May 2024 00:41:54 -0700 Subject: [PATCH] email changes --- src/send_email.py | 37 ++++++++++++++++++++----------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/src/send_email.py b/src/send_email.py index 3c86cf2..1740dd2 100644 --- a/src/send_email.py +++ b/src/send_email.py @@ -29,20 +29,23 @@ message["To"] = RECEIVER_EMAIL message["Subject"] = os.getenv("SUBJECT") -# Execute the command to get output -SURF = subprocess.run( - ["curl", os.getenv("COMMAND")], capture_output=True, text=True, check=True -) -if SURF.returncode == 0: # Check if command executed successfully - BODY = SURF.stdout -else: - BODY = "Failed to execute curl command." -message.attach(MIMEText(BODY, "plain")) - -# Connect to the SMTP server -with smtplib.SMTP(SMTP_SERVER, PORT) as server: - server.starttls() # Secure the connection - server.login(SENDER_EMAIL, PASSWORD) - text = message.as_string() - server.sendmail(SENDER_EMAIL, RECEIVER_EMAIL, text) - print("Email sent successfully.") +def send_user_email(): + # Execute the command to get output + SURF = subprocess.run( + ["curl", os.getenv("COMMAND")], capture_output=True, text=True, check=True + ) + if SURF.returncode == 0: # Check if command executed successfully + BODY = SURF.stdout + else: + BODY = "Failed to execute curl command." + message.attach(MIMEText(BODY, "plain")) + + # Connect to the SMTP server + with smtplib.SMTP(SMTP_SERVER, PORT) as server: + server.starttls() # Secure the connection + server.login(SENDER_EMAIL, PASSWORD) + text = message.as_string() + server.sendmail(SENDER_EMAIL, RECEIVER_EMAIL, text) + print("Email sent successfully.") + +send_user_email() \ No newline at end of file