This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: An email and MIME handling package - Add support to send CC of email
Type: enhancement Stage: resolved
Components: Documentation, email Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Nonickname, barry, docs@python, eric.smith, r.david.murray
Priority: normal Keywords:

Created on 2017-03-09 13:10 by Nonickname, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (9)
msg289291 - (view) Author: Jack (Nonickname) Date: 2017-03-09 13:10
Currently using the package we can only define emails in the 'TO'
as shown here:
https://docs.python.org/2/library/email-examples.html#email-examples

There is no support for email to be sent as CC or BCC which is useful quality in many emails. Please see if this can be added.
msg289292 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-03-09 13:22
The examples don't cover it, but look at the documentation for setting arbitrary mail headers such as CC.

And look at smtplib.SMTP.sendmail() on sending a message to arbitrary recipients (to, cc, or bcc are all the same):
https://docs.python.org/2/library/smtplib.html#smtplib.SMTP.sendmail
msg289293 - (view) Author: Jack (Nonickname) Date: 2017-03-09 13:34
But this is what I mean.. It shouldn't be arbitrary.
When you define CC you want him as CC not as another one in the TO.
This is why I said this is enhancement request.
msg289294 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-03-09 13:38
So, you want to improve the examples? I wouldn't be opposed to that. I don't see that there's any code to change.
msg289295 - (view) Author: Jack (Nonickname) Date: 2017-03-09 13:42
I think you missundersttod. I showed the example page just so you would understand what I am talking about.
Let me explain it better:
msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you

Works.

msg['Subject'] = 'The contents of %s' % textfile
msg['From'] = me
msg['To'] = you
msg['CC'] = x
msg['BCC'] = y

won't work. It doesn't know what is CC and BCC.
This is why I opened this request to modify the package to support it.
msg289296 - (view) Author: Jack (Nonickname) Date: 2017-03-09 13:43
Please see the stack overflow question:
http://stackoverflow.com/questions/42696100/python-smtp-send-email-with-cc
msg289297 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2017-03-09 13:53
You need to review how SMTP works. The contents of the mail message have no bearing on where messages are sent. That's exactly how BCC works: there's nothing in the message telling you who is BCC'd, but the mail is still sent to the BCC recipients, via SMTP.

Similarly, you could have the message say that someone@example.com is in the To: header, but not send it to them via SMTP.

I'm on the fence about including this in the examples.

In any event, this bug tracker is not a place for an email tutorial. From your SO link, there's a reference (by user xyref) to another question which explains this in detail: http://stackoverflow.com/questions/1546367/python-how-to-send-mail-with-to-cc-and-bcc. This completely explains the issue.
msg289298 - (view) Author: Jack (Nonickname) Date: 2017-03-09 13:59
"I'm on the fence about including this in the examples."

Think of it this way.. Including it in the docs would have prevented this question.
It can be just a side note it doesn't have to be a whole example.

Thx.
msg289299 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2017-03-09 14:01
If you use smtplib.send_message in python3, it will do what you want (including stripping BCC headers before sending the message).

If someone wants to create a PR to add an example of what Eric is talking about (specifying additional senders in smtplib.sendmail to match what is in the CC headers) please open a new issue with a PR (which may or may not get accepted :). I don't think it is worth doing, myself, but I won't object if others think it enhances the docs.
History
Date User Action Args
2022-04-11 14:58:44adminsetgithub: 73957
2017-03-09 14:01:02r.david.murraysetmessages: + msg289299
2017-03-09 13:59:09Nonicknamesetstatus: open -> closed

messages: + msg289298
2017-03-09 13:53:34eric.smithsetmessages: + msg289297
2017-03-09 13:44:54serhiy.storchakasetnosy: + barry, r.david.murray
components: + email
2017-03-09 13:43:36Nonicknamesetmessages: + msg289296
2017-03-09 13:42:28Nonicknamesetmessages: + msg289295
2017-03-09 13:38:05eric.smithsetnosy: + docs@python
messages: + msg289294

assignee: docs@python
components: + Documentation
2017-03-09 13:35:10Nonicknamesetstatus: closed -> open
2017-03-09 13:34:59Nonicknamesetmessages: + msg289293
2017-03-09 13:22:39eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg289292

resolution: not a bug
stage: resolved
2017-03-09 13:10:10Nonicknamecreate