Make email template placeholders configurable via environment variables
This commit is contained in:
+9
-12
@@ -15,9 +15,6 @@ from .email_sender import send_email, EmailError, load_template
|
||||
|
||||
logger = logging.getLogger("scraibe.tasks")
|
||||
|
||||
# Contact email used in templates; can be overridden via env
|
||||
CONTACT_EMAIL = os.getenv("EMAIL_CONTACT_ADDRESS", "support@example.com")
|
||||
|
||||
|
||||
def get_queue_position(task_id: str) -> int:
|
||||
"""
|
||||
@@ -42,6 +39,7 @@ def get_queue_position(task_id: str) -> int:
|
||||
def send_initial_email(to: str, queue_pos: int):
|
||||
"""
|
||||
Send initial confirmation email with queue position using HTML template.
|
||||
Static placeholders (contact_email, css_path) come from env via load_template.
|
||||
"""
|
||||
subject = "ScrAIbe: Your transcription request has been received"
|
||||
|
||||
@@ -61,17 +59,16 @@ def send_initial_email(to: str, queue_pos: int):
|
||||
"You will receive an email with your transcript (and summary, if requested) "
|
||||
"once processing is complete.\n\n"
|
||||
"If you have any questions, contact us at "
|
||||
f"{CONTACT_EMAIL}.\n\n"
|
||||
f"{os.getenv('EMAIL_CONTACT_ADDRESS', 'support@example.com')}.\n\n"
|
||||
"This is an automated message from ScrAIbe.\n"
|
||||
)
|
||||
|
||||
# Build HTML using template
|
||||
# Build HTML using template; only dynamic value is queue_position
|
||||
html = None
|
||||
try:
|
||||
html = load_template(
|
||||
"upload_notification_template.html",
|
||||
queue_position=str(queue_pos) if queue_pos > 0 else "the queue",
|
||||
contact_email=CONTACT_EMAIL,
|
||||
)
|
||||
except EmailError as e:
|
||||
logger.warning("Failed to render upload notification template: %s", e)
|
||||
@@ -92,6 +89,7 @@ def send_success_email(
|
||||
):
|
||||
"""
|
||||
Send final email with transcript and attachments using HTML template.
|
||||
Static placeholders (contact_email, css_path) come from env via load_template.
|
||||
"""
|
||||
subject = "ScrAIbe: Your transcript is ready"
|
||||
|
||||
@@ -114,16 +112,15 @@ def send_success_email(
|
||||
"\n"
|
||||
"Job ID: " + str(task_id) + "\n\n"
|
||||
"If you have any questions, contact us at "
|
||||
f"{CONTACT_EMAIL}.\n\n"
|
||||
f"{os.getenv('EMAIL_CONTACT_ADDRESS', 'support@example.com')}.\n\n"
|
||||
"This is an automated message from ScrAIbe.\n"
|
||||
)
|
||||
|
||||
# Build HTML using template
|
||||
# Build HTML using template; no dynamic placeholders needed
|
||||
html = None
|
||||
try:
|
||||
html = load_template(
|
||||
"success_template.html",
|
||||
contact_email=CONTACT_EMAIL,
|
||||
)
|
||||
except EmailError as e:
|
||||
logger.warning("Failed to render success template: %s", e)
|
||||
@@ -144,6 +141,7 @@ def send_success_email(
|
||||
def send_error_email(to: str, error_message: str, task_id: str):
|
||||
"""
|
||||
Send error notification email using HTML template.
|
||||
Static placeholders (contact_email, css_path) come from env via load_template.
|
||||
"""
|
||||
subject = "ScrAIbe: Error with your transcription request"
|
||||
|
||||
@@ -155,17 +153,16 @@ def send_error_email(to: str, error_message: str, task_id: str):
|
||||
"Job ID: " + str(task_id) + "\n\n"
|
||||
"Please contact your administrator if the problem persists.\n\n"
|
||||
"If you have any questions, contact us at "
|
||||
f"{CONTACT_EMAIL}.\n\n"
|
||||
f"{os.getenv('EMAIL_CONTACT_ADDRESS', 'support@example.com')}.\n\n"
|
||||
"This is an automated message from ScrAIbe.\n"
|
||||
)
|
||||
|
||||
# Build HTML using template
|
||||
# Build HTML using template; only dynamic placeholder is exception
|
||||
html = None
|
||||
try:
|
||||
html = load_template(
|
||||
"error_notification_template.html",
|
||||
exception=str(error_message),
|
||||
contact_email=CONTACT_EMAIL,
|
||||
)
|
||||
except EmailError as e:
|
||||
logger.warning("Failed to render error template: %s", e)
|
||||
|
||||
Reference in New Issue
Block a user