Skip to content

fix(email): add email SMTP STARTTLS fallback - #12161

Closed
hxp-plus wants to merge 1 commit into
NousResearch:mainfrom
hxp-plus:main
Closed

fix(email): add email SMTP STARTTLS fallback#12161
hxp-plus wants to merge 1 commit into
NousResearch:mainfrom
hxp-plus:main

Conversation

@hxp-plus

@hxp-plus hxp-plus commented Apr 18, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Fixes SMTP connection handling in the email gateway so both implicit TLS on port 465 and STARTTLS on port 587 work correctly.

Previously, the adapter expects a plain SMTP connection upgraded with STARTTLS on port 587 and can not handle SMTP servers with port 465 with SMTP SSL. This PR unifies SMTP connection paths behind a single flow:

  1. Probe whether the target SMTP server supports STARTTLS
  2. If STARTTLS is supported, connect with smtplib.SMTP(...) and upgrade via starttls(...)
  3. Otherwise, connect with smtplib.SMTP_SSL(...)

This keeps 587-compatible servers working while preserving support for 465-only SMTP setups.

Related Issue

Fixes #11842

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Unified SMTP connection setup in gateway/platforms/email.py
  • Added STARTTLS capability probing before selecting the SMTP transport
  • Updated all 3 SMTP call sites to use the shared connection logic:
    • SMTP connection test in connect()
    • Message sending in _send_email()
    • Attachment sending in _send_email_with_attachment()
  • Added regression coverage in tests/gateway/test_email.py for:
    • STARTTLS-capable SMTP servers
    • SMTP_SSL fallback when STARTTLS is unavailable
    • Send, send-with-attachment, and connect flows

How to Test

  1. Configure the email gateway with an SMTP server that uses STARTTLS on port 587 and verify connect() and message sending still work
  2. Configure the email gateway with an SMTP server that uses implicit TLS on port 465 and verify connect() and message sending work via SMTP_SSL
  3. Run:
    • scripts/run_tests.sh tests/gateway/test_email.py -q
    • scripts/run_tests.sh tests/gateway/ -q

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Linux

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility
    guide
    — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

N/A

@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/email Email (IMAP/SMTP) adapter labels Apr 23, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix with #13564 which also adds SMTP port 465 support. Both address #11842.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@hxp-plus

Copy link
Copy Markdown
Contributor Author

This issue is solved in lateset code. Closing the issue.

@hxp-plus hxp-plus closed this Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P2 Medium — degraded but workaround exists platform/email Email (IMAP/SMTP) adapter type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Email gateway fails on SMTP port 465 — uses STARTTLS instead of SMTP_SSL

2 participants