modify welcome message path
This commit is contained in:
@@ -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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user