fix(email): use SMTP_SSL for port 465 and fall back to IPv4 on timeout - #46061
Closed
liuhao1024 wants to merge 1 commit into
Closed
fix(email): use SMTP_SSL for port 465 and fall back to IPv4 on timeout#46061liuhao1024 wants to merge 1 commit into
liuhao1024 wants to merge 1 commit into
Conversation
Port 465 expects implicit TLS (SMTP_SSL) from the first byte. The email adapter always used SMTP() + starttls(), which is correct for port 587 but hangs/fails on port 465 providers (e.g., Swiss ISPs). Additionally, when the SMTP host has AAAA DNS records but IPv6 is unreachable, socket.create_connection() tries IPv6 first and hangs until timeout. Add an IPv4 fallback via AF_INET socket. Extract _connect_smtp() helper to consolidate the 4 duplicate SMTP connection sites into a single method with correct protocol selection and IPv6 fallback logic.
Contributor
|
Your SMTP_SSL port-465 fix was cherry-picked onto current Thanks for the fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Fixes the Email gateway adapter to use
SMTP_SSL(implicit TLS) for port 465 connections and adds IPv4 fallback when IPv6 is unreachable. Previously, the adapter always usedSMTP()+starttls(), which is correct for port 587 but causes hangs/failures on port 465 providers.Related Issue
Fixes #46018
Type of Change
Changes Made
gateway/platforms/email.py: Extracted_connect_smtp()helper that selectsSMTP_SSLfor port 465 andSMTP+STARTTLSfor other ports. Added IPv4 fallback when the default connection times out (handles hosts with AAAA records on networks without IPv6 routing). Replaced 4 duplicate SMTP connection sites with calls to the helper.tests/gateway/test_email.py: AddedTestConnectSmtpclass with 4 tests: port 587 uses SMTP+STARTTLS, port 465 uses SMTP_SSL, IPv6 timeout falls back to IPv4 for port 587, and IPv6 timeout falls back to IPv4 for port 465.How to Test
EMAIL_SMTP_PORT=465)SMTP_SSLpytest tests/gateway/test_email.py -x -q— all 66 tests passChecklist
Code
fix(scope):,feat(scope):, etc.)pytest tests/gateway/test_email.py -qand all tests passDocumentation & Housekeeping
docs/, docstrings) — or N/Acli-config.yaml.exampleif I added/changed config keys — or N/ACONTRIBUTING.mdorAGENTS.mdif I changed architecture or workflows — or N/ACode Intelligence
gateway/platforms/email.py(_connect_smtp,_send_email,_send_email_with_attachments,_send_email_with_attachment,connect)imaplib.IMAP4_SSL(implicit TLS) — this fix brings SMTP to parity