From 28b8d57b279a79a631c566a64e62792a9ee4297e Mon Sep 17 00:00:00 2001 From: kbe Date: Sun, 20 Jul 2025 15:44:52 +0200 Subject: [PATCH] fix: Use SMTP server instead of gmail The script was using gmail as SMTP server. Or the script uses a custom SMTP one. --- .env.example | 19 +++++++++++-------- .gitignore | 6 ++++++ book_crossfit.py | 2 +- session_notifier.py | 23 ++++++++++++++++++++--- 4 files changed, 38 insertions(+), 12 deletions(-) diff --git a/.env.example b/.env.example index 78104a7..036cc04 100644 --- a/.env.example +++ b/.env.example @@ -1,14 +1,17 @@ -# Configuration -CROSSFIT_USERNAME=Kevin8407 -CROSSFIT_PASSWORD=9vx03OSE +# CrossFit booking credentials +CROSSFIT_USERNAME=your_username +CROSSFIT_PASSWORD=your_password # Notification settings ENABLE_EMAIL_NOTIFICATIONS=true ENABLE_TELEGRAM_NOTIFICATIONS=false -EMAIL_FROM=no-reply@cyanet.fr -EMAIL_TO=kbataille@vivaldi.net -EMAIL_PASSWORD=BV3GzqHjsSx5A6TE +# Email notification credentials +SMTP_SERVER=mail.infomaniak.com +EMAIL_FROM=your_email +EMAIL_TO=recipient_email +EMAIL_PASSWORD=email_password -TELEGRAM_TOKEN= -TELEGRAM_CHAT_ID +# Telegram notification credentials +TELEGRAM_TOKEN=your_telegram_token +TELEGRAM_CHAT_ID=your_chat_id diff --git a/.gitignore b/.gitignore index c925db7..4544309 100644 --- a/.gitignore +++ b/.gitignore @@ -178,3 +178,9 @@ poetry.toml pyrightconfig.json # End of https://www.toptal.com/developers/gitignore/api/python + +# Docker +docker-compose.override.yml +docker-compose.yml +Dockerfile +.dockerignore diff --git a/book_crossfit.py b/book_crossfit.py index 9d98b3b..584a109 100755 --- a/book_crossfit.py +++ b/book_crossfit.py @@ -11,4 +11,4 @@ if __name__ == "__main__": # Start continuous booking loop booker.run() - logging.info("Script completed") + logging.info("Script completed") \ No newline at end of file diff --git a/session_notifier.py b/session_notifier.py index 5aba62f..924cd6d 100644 --- a/session_notifier.py +++ b/session_notifier.py @@ -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): """