🛡️ Warracker is an open source, self-hostable warranty tracker to monitor expirations, store receipts, files. You own the data, your rules!
Fix #201: unify SMTP sender address variables
Omega (QA)821295161366
diff --git a/backend/auth_routes.py b/backend/auth_routes.pyindex 87854d7..a574ae3 100644--- a/backend/auth_routes.py+++ b/backend/auth_routes.py@@ -765,7 +765,11 @@ def send_password_reset_email(recipient_email, reset_link):smtp_password = open(os.environ.get('SMTP_PASSWORD_FILE'), 'r').read().strip()smtp_use_tls = os.environ.get('SMTP_USE_TLS', 'true').lower() == 'true'smtp_use_ssl = os.environ.get('SMTP_USE_SSL', 'false').lower() == 'true'- sender_email = os.environ.get('SMTP_SENDER_EMAIL', '[email protected]')+ try:+ from .utils import get_smtp_from_address+ except ImportError:+ from utils import get_smtp_from_address+ sender_email = get_smtp_from_address()app_name = "Warracker"subject = f"Password Reset - {app_name}"diff --git a/backend/notifications.py b/backend/notifications.pyindex 63f90e3..46b8b8e 100644--- a/backend/notifications.py+++ b/backend/notifications.py@@ -227,11 +227,12 @@ def format_expiration_email(user, warranties, get_db_connection, release_db_conn# Create a MIMEMultipart object for both text and HTMLmsg = MIMEMultipart('alternative')msg['Subject'] = subject- # use SMTP_FROM_ADDRESS if provided, otherwise use SMTP_USERNAME or a default value as below- _from_address = os.environ.get('SMTP_FROM_ADDRESS')- if _from_address is None:- _from_address = os.environ.get('SMTP_USERNAME', '[email protected]')- msg['From'] = _from_address+ # Single canonical sender variable (issue #201)+ try:+ from .utils import get_smtp_from_address+ except ImportError:+ from utils import get_smtp_from_address+ msg['From'] = get_smtp_from_address()msg['To'] = user['email']part1 = MIMEText(text_body, 'plain')@@ -299,7 +300,7 @@ def process_email_notifications(all_warranties, eligible_user_ids, is_manual, ge# Get SMTP settings from environment variablessmtp_host = os.environ.get('SMTP_HOST', 'localhost')smtp_port = int(os.environ.get('SMTP_PORT', '1025'))- smtp_username = os.environ.get('SMTP_USERNAME', '[email protected]')+ smtp_username = os.environ.get('SMTP_USERNAME') # no fake default (issue #201)smtp_password = os.environ.get('SMTP_PASSWORD', '')if os.environ.get('SMTP_PASSWORD_FILE'):smtp_password = open(os.environ.get('SMTP_PASSWORD_FILE'), 'r').read().strip()@@ -380,7 +381,7 @@ def process_email_notifications(all_warranties, eligible_user_ids, is_manual, gerelease_db_connection)try:- server.sendmail(smtp_username, email, msg.as_string())+ server.sendmail(smtp_username or msg['From'], email, msg.as_string())last_notification_sent[email] = timestampemails_sent += 1logger.info(f"Email sent to {email} for {len(user_data['warranties'])} warranties")diff --git a/backend/utils.py b/backend/utils.pyindex bd8361a..57a9b5a 100644--- a/backend/utils.py+++ b/backend/utils.py@@ -3,6 +3,22 @@Shared utility functions for the Warracker application"""+def get_smtp_from_address():+ """Resolve the sender From address for outgoing mail (issue #201).++ Precedence: SMTP_FROM_ADDRESS > SMTP_SENDER_EMAIL (legacy) >+ SMTP_USERNAME > default. A single documented variable+ (SMTP_FROM_ADDRESS) is the canonical one.+ """+ import os+ return (+ os.environ.get('SMTP_FROM_ADDRESS')+ or os.environ.get('SMTP_SENDER_EMAIL')+ or os.environ.get('SMTP_USERNAME')+ or '[email protected]'+ )++def allowed_file(filename):"""Check if the file extension is allowed"""ALLOWED_EXTENSIONS = {'pdf', 'png', 'jpg', 'jpeg', 'zip', 'rar', 'webp', 'gif'}