Gamortsey commited on
Commit
f0a56b8
·
verified ·
1 Parent(s): 364c0c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
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(recipient, subject, body, default_from="noreply@example.com"):
271
- q_subject = urllib.parse.quote(subject or "")
272
- q_body = urllib.parse.quote(body or "")
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["Subject"] = subject or ""
280
- msg.set_content(body or "")
 
 
 
 
 
281
 
282
- timestamp = int(time.time())
283
- fname = f"/content/email_draft_{timestamp}.eml"
284
  with open(fname, "wb") as f:
285
- f.write(bytes(msg.as_string(), "utf-8"))
 
 
 
 
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
  # ============================