fix: Use SMTP server instead of gmail

The script was using gmail as SMTP server. Or the script uses
a custom SMTP one.
This commit is contained in:
kbe
2025-07-20 15:44:52 +02:00
parent be27046d6c
commit 28b8d57b27
4 changed files with 38 additions and 12 deletions

View File

@@ -1,8 +1,10 @@
import smtplib
import os
import logging
from email.message import EmailMessage
from telegram import Bot
class SessionNotifier:
"""
A class to handle notifications for session bookings.
@@ -39,6 +41,9 @@ class SessionNotifier:
Args:
message (str): The message content to be sent in the email
"""
logging.debug("Sending email notification")
logging.debug(f"Email credentials: {self.email_credentials}")
# Create an EmailMessage object
email = EmailMessage()
email.set_content(message)
@@ -51,9 +56,21 @@ class SessionNotifier:
email['Subject'] = 'Session Booking Notification'
# Send the email using smtplib
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(self.email_credentials['from'], self.email_credentials['password'])
smtp.send_message(email)
try:
smtp_server = os.environ.get("SMTP_SERVER")
if not smtp_server:
logging.error("SMTP server not configured in environment variables")
raise ValueError("SMTP server not configured")
with smtplib.SMTP_SSL(smtp_server, 465) as smtp:
logging.debug(f"Connecting to SMTP server: {smtp_server}")
smtp.login(self.email_credentials['from'], self.email_credentials['password'])
logging.debug("Logged in to SMTP server")
smtp.send_message(email)
logging.debug("Email sent successfully")
except Exception as e:
logging.error(f"Failed to send email: {str(e)}")
raise
def send_telegram_notification(self, message):
"""