File size: 1,121 Bytes
a4c92de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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}")