From 79317482aaed3632c5072cf723426481cb1cb6c4 Mon Sep 17 00:00:00 2001 From: Marius Robert Macamete Date: Wed, 10 Sep 2025 11:38:01 +0300 Subject: [PATCH] modify welcome message path --- .../server/utils/welcome_email.py | 54 ++++++++++++++----- 1 file changed, 41 insertions(+), 13 deletions(-) diff --git a/transportmanager/server/utils/welcome_email.py b/transportmanager/server/utils/welcome_email.py index b701a3f..8d28ff7 100644 --- a/transportmanager/server/utils/welcome_email.py +++ b/transportmanager/server/utils/welcome_email.py @@ -1,19 +1,31 @@ import os -from utils.email import send_gmail_with_attachment import logging +from utils.email import send_gmail_with_attachment + class WelcomeMessage: - def __init__(self, name, email): + """ + Sends a welcome email with an optional attached user manual (PDF). + + - Looks for the manual in SERVER_ASSETS_DIR (env) or defaults to ../assets next to this file. + - Manual filename can be customized with WELCOME_MANUAL_FILENAME (env), default: manual.pdf. + """ + + def __init__(self, name: str, email: str): self.name = name self.email = email - self.subject = 'Welcome to Order Go - TMS - Your Account is Ready' - self.assets_folder = os.path.abspath( - os.path.join(os.path.dirname(__file__), "..", "assets") - ) - self.manual = os.path.join(self.assets_folder, "manual.pdf") - print(self.manual) - logging.info(self.manual) - self.body = f''' + self.subject = "Welcome to Order Go - TMS - Your Account is Ready" + + # Allow overriding assets folder and manual filename via env for containerized deployments. + default_assets = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "assets")) + self.assets_folder = os.getenv("SERVER_ASSETS_DIR", default_assets) + self.manual_filename = os.getenv("WELCOME_MANUAL_FILENAME", "manual.pdf") + self.manual = os.path.join(self.assets_folder, self.manual_filename) + + logging.info("WelcomeMessage assets dir: %s", self.assets_folder) + logging.info("WelcomeMessage manual path: %s", self.manual) + + self.body = f""" Dear {self.name}, @@ -28,7 +40,23 @@ class WelcomeMessage: Sincerely, The Order Go - TMS Team - ''' - + """ + def send_email(self): - send_gmail_with_attachment(to_email=self.email, subject=self.subject, body=self.body, attachment_path=self.manual) + # Verify manual existence early and give a clear, actionable error if missing. + if not os.path.isfile(self.manual): + raise FileNotFoundError( + f"Attachment file not found: {self.manual}\n" + f"Tips:\n" + f" - Ensure the file is present in the container image at runtime.\n" + f" - If building with Docker, add: COPY transportmanager/server/assets/ /app/server/assets/\n" + f" - Or set SERVER_ASSETS_DIR to a directory that contains {self.manual_filename}\n" + f" - Current assets folder resolved to: {self.assets_folder}" + ) + + send_gmail_with_attachment( + to_email=self.email, + subject=self.subject, + body=self.body, + attachment_path=self.manual, + )