Skip to content

Commit

Permalink
email changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ryansurf committed May 24, 2024
1 parent 19b6da8 commit dff448f
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/send_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit dff448f

Please sign in to comment.