Spaces:
Running
on
Zero
Running
on
Zero
| import os | |
| import smtplib | |
| import requests | |
| from email.mime.text import MIMEText | |
| from email.mime.multipart import MIMEMultipart | |
| EMAIL_USER = os.getenv("EMAIL_USER") | |
| EMAIL_PASS = os.getenv("EMAIL_PASS") | |
| def get_user_ip(): | |
| try: | |
| return requests.get("https://api.ipify.org", timeout=5).text | |
| except requests.RequestException: | |
| return "Unavailable" | |
| def send_email_notification(ip_address, user_message): | |
| if not EMAIL_USER or not EMAIL_PASS: | |
| print("[Notifier] Missing EMAIL_USER or EMAIL_PASS.") | |
| return | |
| subject = "RezAI Used" | |
| body = f"A new user interacted with RezAi.\n\nIP Address: {ip_address}\nMessage: {user_message}" | |
| msg = MIMEMultipart() | |
| msg["From"] = EMAIL_USER | |
| msg["To"] = EMAIL_USER | |
| msg["Subject"] = subject | |
| msg.attach(MIMEText(body, "plain")) | |
| try: | |
| with smtplib.SMTP("smtp.gmail.com", 587) as server: | |
| server.starttls() | |
| server.login(EMAIL_USER, EMAIL_PASS) | |
| server.sendmail(EMAIL_USER, EMAIL_USER, msg.as_string()) | |
| except Exception as e: | |
| print(f"[Notifier] Email sending error: {e}") | |