X Tutup
The Wayback Machine - https://web.archive.org/web/20240112011921/https://github.com/python/cpython/issues/113658
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Since Python 3.12.1, SMTP.send_message() fails to extract 'RCPT TO' if Cc + Bcc are set #113658

Open
adrienverge opened this issue Jan 2, 2024 · 0 comments
Labels
type-bug An unexpected behavior, bug, or error

Comments

@adrienverge
Copy link

adrienverge commented Jan 2, 2024

Bug report

Bug description:

Summary: after upgrading from Python 3.12.0 to 3.12.1, the to_addrs argument of smtplib.SMTP.send_message() is no longer automatically inferred from the email contents, as they were before and as they should according to the documentation. This seems to occur only if Cc and Bcc are both set and empty.

Reproduction:

  1. Install Python 3.12.1.

  2. Run a TCP server on localhost:1025 that simulates a SMTP server, e.g. with netcat: nc -v -l 1025.

  3. Use Python smtplib.SMTP.send_message() to send an email:

    from email.mime.text import MIMEText
    import smtplib
    msg = MIMEText('Email body.')
    msg['From'] = 'Me <me@me.me>'
    msg['To'] = 'You <you@you.you>'
    msg['Cc'] = ''
    msg['Bcc'] = ''
    smtp = smtplib.SMTP('localhost', 1025)
    smtp.send_message(msg)
  4. Optionally print(msg) to see the exact bytes being sent:

     Content-Type: text/plain; charset="us-ascii"
     MIME-Version: 1.0
     Content-Transfer-Encoding: 7bit
     From: Me <me@me.me>
     To: You <you@you.you>
     Cc: 
     Bcc: 
     
     Email body.
    
  5. Receive the email and see the bug. For instance with netcat, simulate the SMTP protocol by typing 220 HELO then 220 HELO then 250 OK:

    Ncat: Version 7.93 ( https://nmap.org/ncat )
    Ncat: Listening on :::1025
    Ncat: Listening on 0.0.0.0:1025
    Ncat: Connection from ::1.
    Ncat: Connection from ::1:42194.
    220 HELO
    ehlo localhost.localdomain
    220 HELO
    mail FROM:<me@me.me>
    250 OK
    rcpt TO:<>
    

    In the data received, rcpt TO:<> should be rcpt TO:<you@you.you>.

Possibles fixes to avoid this bug:

  • Downgrade to Python 3.12.0.
  • Remove either of Cc or Bcc from the message.
  • Explicitely set to_addrs=... in SMTP.send_message().

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant
X Tutup