[UPDT] HORILLA_AUTOMATIONS: Prevent UnboundLocalError by safely initializing from_email and reply_to with fallback

This commit is contained in:
Horilla
2025-07-24 15:08:01 +05:30
parent b571f7ed79
commit 820c84287c

View File

@@ -406,14 +406,19 @@ def send_mail(request, automation, instance):
cc = cc_emails
email_backend = ConfiguredEmailBackend()
display_email_name = email_backend.dynamic_from_email_with_display_name
if request:
default_email = email_backend.dynamic_from_email_with_display_name
from_email = default_email
reply_to = [default_email]
if request and hasattr(request, "user") and hasattr(request.user, "employee_get"):
try:
display_email_name = f"{request.user.employee_get.get_full_name()} <{request.user.employee_get.email}>"
user = request.user.employee_get
display_email_name = f"{user.get_full_name()} <{user.email}>"
from_email = display_email_name
reply_to = [display_email_name]
except:
logger.error(Exception)
except Exception as e:
logger.error(f"Error generating user-based email display name: {e}")
if pk_or_text and request and to_emails:
attachments = []