fix(diagnose): prioritize Resend check over blocked SMTP sockets
Browse files- routes/v1/alerts.py +15 -39
routes/v1/alerts.py
CHANGED
|
@@ -149,31 +149,7 @@ async def diagnose_smtp(to: str = "john.albarka.ibrahim@gmail.com"):
|
|
| 149 |
"password_len": len(EMAIL_SMTP_PASSWORD) if EMAIL_SMTP_PASSWORD else 0,
|
| 150 |
}
|
| 151 |
|
| 152 |
-
# Test
|
| 153 |
-
try:
|
| 154 |
-
s587 = socket.create_connection((EMAIL_SMTP_HOST, 587), timeout=5)
|
| 155 |
-
s587.close()
|
| 156 |
-
steps["port_587"] = "CONNECTED"
|
| 157 |
-
except Exception as exc:
|
| 158 |
-
steps["port_587"] = f"FAILED: {exc}"
|
| 159 |
-
|
| 160 |
-
# Test 465 (SSL)
|
| 161 |
-
try:
|
| 162 |
-
s465 = socket.create_connection((EMAIL_SMTP_HOST, 465), timeout=5)
|
| 163 |
-
s465.close()
|
| 164 |
-
steps["port_465"] = "CONNECTED"
|
| 165 |
-
except Exception as exc:
|
| 166 |
-
steps["port_465"] = f"FAILED: {exc}"
|
| 167 |
-
|
| 168 |
-
# Test 25
|
| 169 |
-
try:
|
| 170 |
-
s25 = socket.create_connection((EMAIL_SMTP_HOST, 25), timeout=5)
|
| 171 |
-
s25.close()
|
| 172 |
-
steps["port_25"] = "CONNECTED"
|
| 173 |
-
except Exception as exc:
|
| 174 |
-
steps["port_25"] = f"FAILED: {exc}"
|
| 175 |
-
|
| 176 |
-
# Test Resend HTTPS dispatch
|
| 177 |
from config import RESEND_API_KEY, RESEND_FROM_ADDRESS
|
| 178 |
steps["resend_key_set"] = bool(RESEND_API_KEY)
|
| 179 |
steps["resend_from"] = RESEND_FROM_ADDRESS
|
|
@@ -186,20 +162,20 @@ async def diagnose_smtp(to: str = "john.albarka.ibrahim@gmail.com"):
|
|
| 186 |
except Exception as exc:
|
| 187 |
steps["resend_dispatch"] = f"FAILED: {exc}"
|
| 188 |
|
| 189 |
-
#
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
|
| 204 |
return JSONResponse(content={"status": "error", "steps": steps})
|
| 205 |
|
|
|
|
| 149 |
"password_len": len(EMAIL_SMTP_PASSWORD) if EMAIL_SMTP_PASSWORD else 0,
|
| 150 |
}
|
| 151 |
|
| 152 |
+
# Test Resend HTTPS dispatch first (instant over port 443)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
from config import RESEND_API_KEY, RESEND_FROM_ADDRESS
|
| 154 |
steps["resend_key_set"] = bool(RESEND_API_KEY)
|
| 155 |
steps["resend_from"] = RESEND_FROM_ADDRESS
|
|
|
|
| 162 |
except Exception as exc:
|
| 163 |
steps["resend_dispatch"] = f"FAILED: {exc}"
|
| 164 |
|
| 165 |
+
# Probe raw SMTP sockets only if Resend is not configured or failed
|
| 166 |
+
try:
|
| 167 |
+
s587 = socket.create_connection((EMAIL_SMTP_HOST, 587), timeout=3)
|
| 168 |
+
s587.close()
|
| 169 |
+
steps["port_587"] = "CONNECTED"
|
| 170 |
+
except Exception as exc:
|
| 171 |
+
steps["port_587"] = f"FAILED: {exc}"
|
| 172 |
+
|
| 173 |
+
try:
|
| 174 |
+
s465 = socket.create_connection((EMAIL_SMTP_HOST, 465), timeout=3)
|
| 175 |
+
s465.close()
|
| 176 |
+
steps["port_465"] = "CONNECTED"
|
| 177 |
+
except Exception as exc:
|
| 178 |
+
steps["port_465"] = f"FAILED: {exc}"
|
| 179 |
|
| 180 |
return JSONResponse(content={"status": "error", "steps": steps})
|
| 181 |
|