Something went wrong. Try again.
Monorepo for Aesthetic.Computer aesthetic.computer
Something went wrong. Try again.
Python
1234567891011121314151617181920212223242526272829#!/usr/bin/env python3"""Send an email from jasellite via Gmail SMTP. Usage: btx-notify.py "subject" "body"Creds read from ~/.config/btx-notify.env (SMTP_SERVER, SMTP_USER, SMTP_PASS, NOTIFY_TO)."""import sys, os, ssl, smtplibfrom email.message import EmailMessage
env = {}for line in open(os.path.expanduser("~/.config/btx-notify.env")): line = line.strip() if not line or line.startswith("#") or "=" not in line: continue k, v = line.split("=", 1) env[k] = v
subject = sys.argv[1] if len(sys.argv) > 1 else "BTX notice"body = sys.argv[2] if len(sys.argv) > 2 else ""
msg = EmailMessage()msg["From"] = env["SMTP_USER"]msg["To"] = env.get("NOTIFY_TO", env["SMTP_USER"])msg["Subject"] = subjectmsg.set_content(body)
with smtplib.SMTP(env.get("SMTP_SERVER", "smtp.gmail.com"), 587, timeout=30) as s: s.starttls(context=ssl.create_default_context()) s.login(env["SMTP_USER"], env["SMTP_PASS"]) s.send_message(msg)print("sent:", subject)