Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -319,14 +319,26 @@ async def health():
|
|
| 319 |
"endpoints": ["/health", "/send", "/status/{job_id}", "/track/open/{job_id}/{email}", "/analytics/{job_id}", "/docs"]
|
| 320 |
}
|
| 321 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 322 |
@app.post("/send")
|
| 323 |
async def send_emails(
|
| 324 |
request: Request,
|
| 325 |
background_tasks: BackgroundTasks,
|
| 326 |
file: UploadFile = File(...),
|
| 327 |
-
# SMTP β
|
| 328 |
-
gmail_user: str = Form(
|
| 329 |
-
gmail_pass: str = Form(
|
| 330 |
# Optional extra SMTP accounts for round-robin (JSON array string)
|
| 331 |
extra_accounts: str = Form("[]"),
|
| 332 |
# Campaign settings
|
|
@@ -354,6 +366,15 @@ async def send_emails(
|
|
| 354 |
if "Email" not in df.columns:
|
| 355 |
raise HTTPException(status_code=400, detail=f"File must have 'Email' column. Found: {list(df.columns)}")
|
| 356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
# Build SMTP list
|
| 358 |
smtp_accounts = [{"user": gmail_user, "pass": gmail_pass}]
|
| 359 |
try:
|
|
|
|
| 319 |
"endpoints": ["/health", "/send", "/status/{job_id}", "/track/open/{job_id}/{email}", "/analytics/{job_id}", "/docs"]
|
| 320 |
}
|
| 321 |
|
| 322 |
+
# ββ Read HF Space secrets once at startup ββββββββββββββββββββββββββββββββββββ
|
| 323 |
+
_DEFAULT_GMAIL_USER = os.getenv("GMAIL_USER", "")
|
| 324 |
+
_DEFAULT_GMAIL_PASS = os.getenv("GMAIL_PASS", "")
|
| 325 |
+
|
| 326 |
+
@app.get("/config")
|
| 327 |
+
async def config():
|
| 328 |
+
"""Returns non-sensitive config so the UI can pre-fill fields."""
|
| 329 |
+
return {
|
| 330 |
+
"gmail_user": _DEFAULT_GMAIL_USER,
|
| 331 |
+
"has_pass": bool(_DEFAULT_GMAIL_PASS),
|
| 332 |
+
}
|
| 333 |
+
|
| 334 |
@app.post("/send")
|
| 335 |
async def send_emails(
|
| 336 |
request: Request,
|
| 337 |
background_tasks: BackgroundTasks,
|
| 338 |
file: UploadFile = File(...),
|
| 339 |
+
# SMTP β falls back to HF Space secrets if left blank
|
| 340 |
+
gmail_user: str = Form(default=""),
|
| 341 |
+
gmail_pass: str = Form(default=""),
|
| 342 |
# Optional extra SMTP accounts for round-robin (JSON array string)
|
| 343 |
extra_accounts: str = Form("[]"),
|
| 344 |
# Campaign settings
|
|
|
|
| 366 |
if "Email" not in df.columns:
|
| 367 |
raise HTTPException(status_code=400, detail=f"File must have 'Email' column. Found: {list(df.columns)}")
|
| 368 |
|
| 369 |
+
# Fall back to HF Space secrets if the UI left the fields blank
|
| 370 |
+
if not gmail_user:
|
| 371 |
+
gmail_user = _DEFAULT_GMAIL_USER
|
| 372 |
+
if not gmail_pass:
|
| 373 |
+
gmail_pass = _DEFAULT_GMAIL_PASS
|
| 374 |
+
|
| 375 |
+
if not gmail_user or not gmail_pass:
|
| 376 |
+
raise HTTPException(status_code=400, detail="No Gmail credentials provided and no GMAIL_USER/GMAIL_PASS secrets configured.")
|
| 377 |
+
|
| 378 |
# Build SMTP list
|
| 379 |
smtp_accounts = [{"user": gmail_user, "pass": gmail_pass}]
|
| 380 |
try:
|