Skip to content

smtplib not honoring bcc header #75235

Closed
Closed

Description

@zoof
mannequin
BPO 31052
Nosy @bitdancer

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2017-07-27.04:34:53.453>
created_at = <Date 2017-07-26.23:43:32.658>
labels = ['invalid', 'type-bug', 'library']
title = 'smtplib not honoring bcc header'
updated_at = <Date 2017-07-27.04:34:53.446>
user = 'https://bugs.python.org/zoof'

bugs.python.org fields:

activity = <Date 2017-07-27.04:34:53.446>
actor = 'r.david.murray'
assignee = 'none'
closed = True
closed_date = <Date 2017-07-27.04:34:53.453>
closer = 'r.david.murray'
components = ['Library (Lib)']
creation = <Date 2017-07-26.23:43:32.658>
creator = 'zoof'
dependencies = []
files = []
hgrepos = []
issue_num = 31052
keywords = []
message_count = 2.0
messages = ['299278', '299293']
nosy_count = 2.0
nosy_names = ['r.david.murray', 'zoof']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue31052'
versions = ['Python 2.7']

Activity

  1. zoof commented on Jul 26, 2017

    zoofmannequin
    MannequinAuthor

    When I try sending an email, using smtplib, with the bcc header set, the bcc header is included in messages send to the "to" and "cc" addresses. According to section 4.5.3 of rfc 822:

    > The contents of this field are not included in copies of the message sent to the primary and secondary  recipients.
    

    So this behavior is incorrect. It should not be up to the mail client to ignore the bcc field.

    Here's a script that can replicate the problem:

    #!/usr/bin/env python

    import smtplib
    from email.MIMEMultipart import MIMEMultipart
    from email.MIMEText import MIMEText
    
    body = "this is a test"
    
    #craft the message
    fromaddr = 'ned@example.com'
    server = smtplib.SMTP('smtp.example.com', 587)
    p = 'Hunter2!'
    subject = "test"
    toaddr = "foo@example.com"
    ccaddr = "bar@example.com"
    bccaddr = "baz@example.com"
    
    msg = MIMEMultipart()

    msg['cc'] = ccaddr
    msg['bcc'] = bccaddr
    msg['From'] = fromaddr
    msg['To'] = toaddr
    msg['Subject'] = subject

    msg.attach(MIMEText(body, 'plain'))

    #send the message
    server.starttls()
    server.login(fromaddr, p)
    text = msg.as_string()
    server.sendmail(fromaddr, toaddr, text)
    server.quit()
  2. added
    stdlibStandard Library Python modules in the Lib/ directory
    type-bugAn unexpected behavior, bug, or error
    on Jul 26, 2017
  3. bitdancer commented on Jul 27, 2017

    @bitdancer
    Member

    smtplib in 2.7 doesn't know anything about RFC822 or any of the replacement RFCs. sendmail accepts a *string*, and doesn't understand or modify anything about that string except the newlines. It is your responsibility not to *add* the BCC header. What you want to do is put the BCC (and CC!) recipients in your toaddr list passed to sendmail, and *not* add a BCC header.

    In Python3 smtplib has a send_message method that accepts a Message object, and that method uses the BCC to inform where to send the message and strips the header before sending. That is, smtplib's send_message method *does* implement RFC5322 behaviors.

  4. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions