Spaces:
Running
on
Zero
Running
on
Zero
| import os | |
| from sendgrid import SendGridAPIClient | |
| from sendgrid.helpers.mail import Mail | |
| SENDGRID_API_KEY = os.getenv("SENDGRID_API_KEY") | |
| EMAIL_TO = os.getenv("EMAIL_TO") | |
| def send_email_notification(user_message): | |
| if not SENDGRID_API_KEY or not EMAIL_TO: | |
| print("[Notifier] Missing SendGrid credentials.") | |
| return | |
| print("[Notifier] Sending email via SendGrid SDK...") | |
| message = Mail( | |
| from_email=EMAIL_TO, | |
| to_emails=EMAIL_TO, | |
| subject="RezAi Interaction", | |
| html_content=f"<strong>Someone sent a message to RezAi:</strong><br><br>{user_message}" | |
| ) | |
| try: | |
| sg = SendGridAPIClient(SENDGRID_API_KEY) | |
| response = sg.send(message) | |
| if response.status_code == 202: | |
| print("[Notifier] β Email sent successfully!") | |
| else: | |
| print(f"[Notifier] β SendGrid SDK failed: {response.status_code} β {response.body}") | |
| except Exception as e: | |
| print(f"[Notifier] β Exception: {e}") | |