modify welcome message path

This commit is contained in:
2025-09-10 11:38:01 +03:00
parent 559e7923a4
commit 79317482aa

View File

@@ -1,19 +1,31 @@
import os import os
from utils.email import send_gmail_with_attachment
import logging import logging
from utils.email import send_gmail_with_attachment
class WelcomeMessage: 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.name = name
self.email = email self.email = email
self.subject = 'Welcome to Order Go - TMS - Your Account is Ready' 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") # 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.manual = os.path.join(self.assets_folder, "manual.pdf") self.assets_folder = os.getenv("SERVER_ASSETS_DIR", default_assets)
print(self.manual) self.manual_filename = os.getenv("WELCOME_MANUAL_FILENAME", "manual.pdf")
logging.info(self.manual) self.manual = os.path.join(self.assets_folder, self.manual_filename)
self.body = f'''
logging.info("WelcomeMessage assets dir: %s", self.assets_folder)
logging.info("WelcomeMessage manual path: %s", self.manual)
self.body = f"""
Dear {self.name}, Dear {self.name},
@@ -28,7 +40,23 @@ class WelcomeMessage:
Sincerely, Sincerely,
The Order Go - TMS Team The Order Go - TMS Team
''' """
def send_email(self): 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,
)