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:
19
.env.example
19
.env.example
@@ -1,14 +1,17 @@
|
|||||||
# Configuration
|
# CrossFit booking credentials
|
||||||
CROSSFIT_USERNAME=Kevin8407
|
CROSSFIT_USERNAME=your_username
|
||||||
CROSSFIT_PASSWORD=9vx03OSE
|
CROSSFIT_PASSWORD=your_password
|
||||||
|
|
||||||
# Notification settings
|
# Notification settings
|
||||||
ENABLE_EMAIL_NOTIFICATIONS=true
|
ENABLE_EMAIL_NOTIFICATIONS=true
|
||||||
ENABLE_TELEGRAM_NOTIFICATIONS=false
|
ENABLE_TELEGRAM_NOTIFICATIONS=false
|
||||||
|
|
||||||
EMAIL_FROM=no-reply@cyanet.fr
|
# Email notification credentials
|
||||||
EMAIL_TO=kbataille@vivaldi.net
|
SMTP_SERVER=mail.infomaniak.com
|
||||||
EMAIL_PASSWORD=BV3GzqHjsSx5A6TE
|
EMAIL_FROM=your_email
|
||||||
|
EMAIL_TO=recipient_email
|
||||||
|
EMAIL_PASSWORD=email_password
|
||||||
|
|
||||||
TELEGRAM_TOKEN=
|
# Telegram notification credentials
|
||||||
TELEGRAM_CHAT_ID
|
TELEGRAM_TOKEN=your_telegram_token
|
||||||
|
TELEGRAM_CHAT_ID=your_chat_id
|
||||||
|
|||||||
6
.gitignore
vendored
6
.gitignore
vendored
@@ -178,3 +178,9 @@ poetry.toml
|
|||||||
pyrightconfig.json
|
pyrightconfig.json
|
||||||
|
|
||||||
# End of https://www.toptal.com/developers/gitignore/api/python
|
# End of https://www.toptal.com/developers/gitignore/api/python
|
||||||
|
|
||||||
|
# Docker
|
||||||
|
docker-compose.override.yml
|
||||||
|
docker-compose.yml
|
||||||
|
Dockerfile
|
||||||
|
.dockerignore
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
import smtplib
|
import smtplib
|
||||||
import os
|
import os
|
||||||
|
import logging
|
||||||
from email.message import EmailMessage
|
from email.message import EmailMessage
|
||||||
from telegram import Bot
|
from telegram import Bot
|
||||||
|
|
||||||
|
|
||||||
class SessionNotifier:
|
class SessionNotifier:
|
||||||
"""
|
"""
|
||||||
A class to handle notifications for session bookings.
|
A class to handle notifications for session bookings.
|
||||||
@@ -39,6 +41,9 @@ class SessionNotifier:
|
|||||||
Args:
|
Args:
|
||||||
message (str): The message content to be sent in the email
|
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
|
# Create an EmailMessage object
|
||||||
email = EmailMessage()
|
email = EmailMessage()
|
||||||
email.set_content(message)
|
email.set_content(message)
|
||||||
@@ -51,9 +56,21 @@ class SessionNotifier:
|
|||||||
email['Subject'] = 'Session Booking Notification'
|
email['Subject'] = 'Session Booking Notification'
|
||||||
|
|
||||||
# Send the email using smtplib
|
# Send the email using smtplib
|
||||||
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
|
try:
|
||||||
smtp.login(self.email_credentials['from'], self.email_credentials['password'])
|
smtp_server = os.environ.get("SMTP_SERVER")
|
||||||
smtp.send_message(email)
|
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):
|
def send_telegram_notification(self, message):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user