From fb1dc3324d5d04d5b056f4069a9d3f533a021cca Mon Sep 17 00:00:00 2001 From: admin Date: Sun, 14 Jun 2026 15:24:08 +0000 Subject: [PATCH] Use logo1.png in emails, inline mail_style.css, attach summary as MD --- misc/error_notification_template.html | 72 +++----------------------- misc/success_template.html | 64 ++--------------------- misc/upload_notification_template.html | 63 ++-------------------- scraibe/email_sender.py | 43 +++++++++++++-- scraibe/tasks.py | 14 +++-- 5 files changed, 66 insertions(+), 190 deletions(-) diff --git a/misc/error_notification_template.html b/misc/error_notification_template.html index 969965a..3363d79 100644 --- a/misc/error_notification_template.html +++ b/misc/error_notification_template.html @@ -4,71 +4,15 @@ Error Notification -
-

Error Notification

-

Dear user:

+ {email_logo} +

Error Notification

+

Dear user,

An error occurred while processing your audio file. This means that something went wrong during the processing of your file, and it could not be completed successfully.

Error details: {exception}

Please check the file and try again. If the problem persists, our support team is here to help.

@@ -78,10 +22,10 @@

Please note that our support team does not have the ability to fix processing errors directly or access the files you have uploaded. They can provide guidance and help troubleshoot any issues you may encounter.

-
-

Thank you for using our transcription service!

-

A.P.Strom

-
+
+

Thank you for using our transcription service!

+

A.P.Strom

+
diff --git a/misc/success_template.html b/misc/success_template.html index 00136d7..6e616e0 100644 --- a/misc/success_template.html +++ b/misc/success_template.html @@ -4,71 +4,15 @@ Transcript Ready -
-

Transcript Ready

-

Dear user:

+ {email_logo} +

Transcript Ready

+

Dear user,

Your file has been successfully processed, and the transcript is now ready. The transcript of your audio or video file is attached to this email.

We hope you find the transcript useful. If you have any questions or need further assistance, please do not hesitate to contact our support team.

diff --git a/misc/upload_notification_template.html b/misc/upload_notification_template.html index d5904d7..27a926d 100644 --- a/misc/upload_notification_template.html +++ b/misc/upload_notification_template.html @@ -5,69 +5,14 @@ Upload Successful
-

Upload Successful

-

Dear user:

+ {email_logo} +

Upload Successful

+

Dear user,

Your file has been successfully uploaded and is now in our processing queue. This means that our system has received your file, and it is waiting to be processed. We will handle your file as soon as possible.

Your current position in the queue is: {queue_position}. This is the order in which your file will be processed. We appreciate your patience as we work through the queue.

We will notify you once your file has been processed. If you have any urgent needs or further questions, feel free to reach out to our support team.

diff --git a/scraibe/email_sender.py b/scraibe/email_sender.py index 9a2061b..33a6be3 100644 --- a/scraibe/email_sender.py +++ b/scraibe/email_sender.py @@ -7,6 +7,7 @@ Supports both plain text and HTML email bodies. Template placeholders are primarily filled via environment variables. """ +import base64 import os import smtplib import logging @@ -53,6 +54,33 @@ def get_email_config(): } +def _load_css(path: str) -> str: + """ + Load CSS file content if it exists. + """ + if not path or not os.path.exists(path): + return "" + with open(path, "r", encoding="utf-8") as f: + return f.read() + + +def _logo1_inline_html() -> str: + """ + Return an inline tag for logo1.png as base64. + Falls back to empty string if not found. + """ + logo_path = os.getenv("EMAIL_LOGO_PATH", "/app/src/misc/logo1.png") + if not os.path.exists(logo_path): + return "" + + try: + with open(logo_path, "rb") as f: + b64 = base64.b64encode(f.read()).decode("utf-8") + return f'A.P.Strom' + except Exception: + return "" + + def build_template_context(**runtime_kwargs: Any) -> Dict[str, Any]: """ Build a context dict for templates from: @@ -61,13 +89,20 @@ def build_template_context(**runtime_kwargs: Any) -> Dict[str, Any]: Environment variables: - EMAIL_CONTACT_ADDRESS: value for {contact_email} - - EMAIL_CSS_PATH: value for {css_path} - - Runtime kwargs are merged on top (e.g. queue_position, exception). + - EMAIL_CSS_PATH: path to mail_style.css (optional; we inline it) + - EMAIL_LOGO_PATH: path to logo1.png (default: /app/src/misc/logo1.png) """ + # Load and inline mail_style.css for consistent email styling + css_path = os.getenv("EMAIL_CSS_PATH", "/app/src/misc/mail_style.css") + css_text = _load_css(css_path) + + # Build inline logo HTML + logo_html = _logo1_inline_html() + ctx: Dict[str, Any] = { "contact_email": os.getenv("EMAIL_CONTACT_ADDRESS", "support@example.com"), - "css_path": os.getenv("EMAIL_CSS_PATH", ""), + "email_css": css_text, + "email_logo": logo_html, } # Runtime values override env if provided diff --git a/scraibe/tasks.py b/scraibe/tasks.py index c4c8f98..3151f7f 100644 --- a/scraibe/tasks.py +++ b/scraibe/tasks.py @@ -39,7 +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. + Static placeholders (contact_email, css, logo) come from env via load_template. """ subject = "ScrAIbe: Your transcription request has been received" @@ -89,7 +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. + Static placeholders (contact_email, css, logo) come from env via load_template. """ subject = "ScrAIbe: Your transcript is ready" @@ -141,7 +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. + Static placeholders (contact_email, css, logo) come from env via load_template. """ subject = "ScrAIbe: Error with your transcription request" @@ -271,6 +271,14 @@ def process_transcription_task( json.dump(json_data, f, indent=2, ensure_ascii=False) attachments.append(json_path) + # MD summary (only when summary is available) + if summary_text: + md_path = tempfile.mktemp(suffix=".md") + with open(md_path, "w", encoding="utf-8") as f: + f.write("# Summary\n\n") + f.write(summary_text) + attachments.append(md_path) + # 5) Send success email send_success_email( to=email_to,