diff --git a/.env.example b/.env.example index e5aa97a..f06282e 100644 --- a/.env.example +++ b/.env.example @@ -10,6 +10,10 @@ WORK_VOL=/opt/docker_auv-python_vols/data HOST_NAME=example.shore.mbari.org GMT_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu/ +# SMTP relay host and port for email notifications (STARTTLS) +SMTP_HOST=localhost +SMTP_PORT=587 + # SSDS API endpoint (set to your dev server as needed) SSDS_API_BASE=https://mooring-ssds.shore.mbari.org/api diff --git a/src/data/lrauv_deployment_plots.py b/src/data/lrauv_deployment_plots.py index f1f6d96..2e5b952 100755 --- a/src/data/lrauv_deployment_plots.py +++ b/src/data/lrauv_deployment_plots.py @@ -38,6 +38,8 @@ from resample import FREQ, LRAUV_OPENDAP_BASE ENV_LRAUV_NOTIFY = "LRAUV_NOTIFY" +ENV_SMTP_HOST = "SMTP_HOST" +ENV_SMTP_PORT = "SMTP_PORT" class DeploymentPlotter: @@ -427,8 +429,18 @@ def _notify( msg["From"] = "auv-python@mbari.org" msg["To"] = resolved msg.set_content(body) + for p in html_paths: + if p.exists(): + msg.add_attachment( + p.read_text(encoding="utf-8"), + subtype="html", + filename=p.name, + ) try: - with smtplib.SMTP("localhost") as s: + smtp_host = os.environ.get(ENV_SMTP_HOST, "localhost") + smtp_port = int(os.environ.get(ENV_SMTP_PORT, "587")) + with smtplib.SMTP(smtp_host, smtp_port) as s: + s.starttls() s.send_message(msg) self.logger.info("Email notification sent to %s", resolved) except Exception as exc: # noqa: BLE001 @@ -742,6 +754,8 @@ def process_command_line(self) -> None: "-v", "--verbose", type=int, + nargs="?", + const=1, default=0, choices=[0, 1, 2], help="Verbosity level (0=warn, 1=info, 2=debug)",