Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -267,22 +267,26 @@ def find_professionals_from_story(story, country=DEFAULT_COUNTRY, results_per_qu
|
|
| 267 |
# ============================
|
| 268 |
# DRAFT (mailto + .eml)
|
| 269 |
# ============================
|
| 270 |
-
def build_mailto_and_eml(
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
mailto = f"mailto:{recipient}?subject={q_subject}&body={q_body}"
|
| 274 |
|
| 275 |
msg = EmailMessage()
|
| 276 |
-
if recipient:
|
| 277 |
-
msg["To"] = recipient
|
| 278 |
msg["From"] = default_from
|
| 279 |
-
msg["
|
| 280 |
-
msg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 281 |
|
| 282 |
-
timestamp = int(time.time())
|
| 283 |
-
fname = f"/content/email_draft_{timestamp}.eml"
|
| 284 |
with open(fname, "wb") as f:
|
| 285 |
-
f.write(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
return mailto, fname
|
| 287 |
|
| 288 |
# ============================
|
|
|
|
| 267 |
# ============================
|
| 268 |
# DRAFT (mailto + .eml)
|
| 269 |
# ============================
|
| 270 |
+
def build_mailto_and_eml(to_addr, subject, body, default_from="noreply@ally.ai"):
|
| 271 |
+
from email.message import EmailMessage
|
| 272 |
+
import time
|
|
|
|
| 273 |
|
| 274 |
msg = EmailMessage()
|
|
|
|
|
|
|
| 275 |
msg["From"] = default_from
|
| 276 |
+
msg["To"] = to_addr
|
| 277 |
+
msg["Subject"] = subject
|
| 278 |
+
msg.set_content(body)
|
| 279 |
+
|
| 280 |
+
# ✅ Save to a writable directory (current working dir or "tmp")
|
| 281 |
+
os.makedirs("tmp", exist_ok=True)
|
| 282 |
+
fname = os.path.join("tmp", f"email_draft_{int(time.time())}.eml")
|
| 283 |
|
|
|
|
|
|
|
| 284 |
with open(fname, "wb") as f:
|
| 285 |
+
f.write(msg.as_bytes())
|
| 286 |
+
|
| 287 |
+
# Create mailto link (this part is fine)
|
| 288 |
+
mailto = f"mailto:{to_addr}?subject={subject}&body={body}"
|
| 289 |
+
|
| 290 |
return mailto, fname
|
| 291 |
|
| 292 |
# ============================
|