Skip to content

gh-80274: Add smtputf8 parameter to smtplib.SMTP.verify() and expn() - #161590

Open
vasiliyk wants to merge 2 commits into
python:mainfrom
vasiliyk:gh-80274-unicode
Open

vasiliyk wants to merge 2 commits into
python:mainfrom
vasiliyk:gh-80274-unicode

Conversation

@vasiliyk

@vasiliyk vasiliyk commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

SMTP.verify() and SMTP.expn() always encoded their argument as ASCII, so a non-ASCII address raised UnicodeEncodeError even on servers advertising SMTPUTF8.

This PR adds a smtputf8 parameter to both methods.

  • When true, the address is sent as UTF-8 with the SMTPUTF8 parameter (RFC 6531 #3.7.4.2), EHLO is negotiated first if needed. SMTPNotSupportedError is raised if the server does not advertise the extension.
  • Without the flag nothing changes

I used an explicit flag rather than auto-detection, mirroring mail().
For a non-ASCII address the flag is clearly needed, but it also matters for an ASCII address:
the SMTPUTF8 parameter tells the server that UTF-8 is acceptable in the reply, so VRFY joe@example.com SMTPUTF8 can return 250 Jő Smith <joe@example.com>, where without the parameter the server must answer 252 or 550 instead.

@read-the-docs-community

read-the-docs-community Bot commented Nov 7, 2026 •

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35876795 | 📁 Comparing 9e7fffc against main (f767423)

  🔍 Preview build  

61 files changed · ± 61 modified

± Modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant