Agent Zero AI framework
improve: test connection send test email to self after auth passes
linuztxbe2587e815aa
diff --git a/plugins/_email_integration/api/test_connection.py b/plugins/_email_integration/api/test_connection.pyindex 9a32d20bd..0cdf55785 100644--- a/plugins/_email_integration/api/test_connection.py+++ b/plugins/_email_integration/api/test_connection.py@@ -8,7 +8,7 @@ from plugins._email_integration.helpers.imap_client import (disconnect_imap,get_highest_uid,)-from plugins._email_integration.helpers.smtp_client import SmtpConfig, test_smtp+from plugins._email_integration.helpers.smtp_client import SmtpConfig, test_smtp, send_replyclass TestConnection(ApiHandler):@@ -21,6 +21,8 @@ class TestConnection(ApiHandler):if account_type == "imap":await self._test_imap(handler, results)await self._test_smtp(handler, results)+ if all(r["ok"] for r in results):+ await self._test_send(handler, results)ok = all(r["ok"] for r in results)return {"success": ok, "results": results}@@ -47,16 +49,18 @@ class TestConnection(ApiHandler):"message": format_error(e),})+ def _smtp_config(self, handler: dict) -> SmtpConfig:+ smtp_server = handler.get("smtp_server") or handler.get("imap_server", "")+ return SmtpConfig(+ server=smtp_server,+ port=int(handler.get("smtp_port", 587)),+ username=handler.get("username", ""),+ password=handler.get("password", ""),+ )+async def _test_smtp(self, handler: dict, results: list[dict]):try:- smtp_server = handler.get("smtp_server") or handler.get("imap_server", "")- cfg = SmtpConfig(- server=smtp_server,- port=int(handler.get("smtp_port", 587)),- username=handler.get("username", ""),- password=handler.get("password", ""),- )- error = await test_smtp(cfg)+ error = await test_smtp(self._smtp_config(handler))if error:results.append({"test": "SMTP", "ok": False, "message": error})else:@@ -71,3 +75,26 @@ class TestConnection(ApiHandler):"ok": False,"message": format_error(e),})++ async def _test_send(self, handler: dict, results: list[dict]):+ try:+ error = await send_reply(+ config=self._smtp_config(handler),+ to=handler.get("username", ""),+ subject="Agent Zero - Connection Test",+ body="This is a test email from Agent Zero email integration.",+ )+ if error:+ results.append({"test": "Send", "ok": False, "message": error})+ else:+ results.append({+ "test": "Send",+ "ok": True,+ "message": "Test email sent to self",+ })+ except Exception as e:+ results.append({+ "test": "Send",+ "ok": False,+ "message": format_error(e),+ })