coderuday21 commited on
Commit
0e5174f
·
1 Parent(s): 7392882

Email API: attach populated ChangeDetection.html report (base64)

Browse files
Files changed (1) hide show
  1. app/notifier.py +5 -3
app/notifier.py CHANGED
@@ -4,6 +4,7 @@ Sends HTML-formatted detection reports via the manager's email API (HTTPS)
4
  or SMTP (e.g. Gmail) when API URL is not set.
5
  Credentials and API URL from environment variables.
6
  """
 
7
  import logging
8
  import os
9
  import re
@@ -115,13 +116,14 @@ def _send_via_api(recipient: str, subject: str, html_body: str):
115
  url = EMAIL_API_URL.strip()
116
  try:
117
  import requests
118
- # API requires all fields; use placeholders when no attachment (empty base64 = "")
 
119
  files = {
120
  "ToEmail": (None, recipient),
121
  "Subject": (None, subject),
122
  "Body": (None, html_body),
123
- "FileName": (None, "report.html"),
124
- "AttachmentBase64": (None, "IA=="), # base64 of single space when no attachment
125
  }
126
  resp = requests.post(
127
  url,
 
4
  or SMTP (e.g. Gmail) when API URL is not set.
5
  Credentials and API URL from environment variables.
6
  """
7
+ import base64
8
  import logging
9
  import os
10
  import re
 
116
  url = EMAIL_API_URL.strip()
117
  try:
118
  import requests
119
+ # Attach the same HTML report as a file so the API can deliver it.
120
+ attachment_b64 = base64.b64encode(html_body.encode("utf-8")).decode("ascii")
121
  files = {
122
  "ToEmail": (None, recipient),
123
  "Subject": (None, subject),
124
  "Body": (None, html_body),
125
+ "FileName": (None, "ChangeDetection.html"),
126
+ "AttachmentBase64": (None, attachment_b64),
127
  }
128
  resp = requests.post(
129
  url,