Files
TMS/transportmanager/server/utils/welcome_email.py

63 lines
2.7 KiB
Python

import os
import logging
from utils.email import send_gmail_with_attachment
class WelcomeMessage:
"""
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"
# 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},
We are pleased to welcome you to Order Go - TMS. Thank you for choosing our platform to support your business needs.
To assist you in getting started, we have attached the User Manual to this email. It provides step-by-step instructions on account setup, feature overview, and best practices for using Order Go - TMS efficiently.
We recommend reviewing the manual at your convenience to become familiar with the system's capabilities. Should you require any further assistance, our support team is available at support@ordergotms.com.
We look forward to supporting your success and building a long-term partnership.
Sincerely,
The Order Go - TMS Team
"""
def send_email(self):
# 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,
)