python: how to send mail with TO, CC and BCC?
I need for testing purposes to populate few hundred email boxes with various messages, and was going to use smtplib for that. But among other things I need to be able to send messages not only TO specific mailboxes, but CC and BCC them as well. It does not look like smtplib supports CC-ing and BCC-ing while sending emails.
Looking for suggestions how to do CC or BCC sending messages from the python script.
(And — no, I'm not creating a script to spam anyone outside of my testing environment.)
python email testing
add a comment |
I need for testing purposes to populate few hundred email boxes with various messages, and was going to use smtplib for that. But among other things I need to be able to send messages not only TO specific mailboxes, but CC and BCC them as well. It does not look like smtplib supports CC-ing and BCC-ing while sending emails.
Looking for suggestions how to do CC or BCC sending messages from the python script.
(And — no, I'm not creating a script to spam anyone outside of my testing environment.)
python email testing
add a comment |
I need for testing purposes to populate few hundred email boxes with various messages, and was going to use smtplib for that. But among other things I need to be able to send messages not only TO specific mailboxes, but CC and BCC them as well. It does not look like smtplib supports CC-ing and BCC-ing while sending emails.
Looking for suggestions how to do CC or BCC sending messages from the python script.
(And — no, I'm not creating a script to spam anyone outside of my testing environment.)
python email testing
I need for testing purposes to populate few hundred email boxes with various messages, and was going to use smtplib for that. But among other things I need to be able to send messages not only TO specific mailboxes, but CC and BCC them as well. It does not look like smtplib supports CC-ing and BCC-ing while sending emails.
Looking for suggestions how to do CC or BCC sending messages from the python script.
(And — no, I'm not creating a script to spam anyone outside of my testing environment.)
python email testing
python email testing
asked Oct 9 '09 at 22:29
user63503
1,882103337
1,882103337
add a comment |
add a comment |
6 Answers
6
active
oldest
votes
Email headers don't matter to the smtp server. Just add the CC and BCC recipients to the toaddrs when you send your email. For CC, add them to the CC header.
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
1
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
3
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
add a comment |
Key thing is to add the recipients as a list of email ids in your sendmail call.
import smtplib
from email.mime.multipart import MIMEMultipart
me = "user63503@gmail.com"
to = "someone@gmail.com"
cc = "anotherperson@gmail.com,someone@yahoo.com"
bcc = "bccperson1@gmail.com,bccperson2@yahoo.com"
rcpt = cc.split(",") + bcc.split(",") + [to]
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subject"
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
msg.attach(my_msg_body)
server = smtplib.SMTP("localhost") # or your smtp server
server.sendmail(me, rcpt, msg.as_string())
server.quit()
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
2
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
2
Leave themsg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments tosendmail
do that).
– Erica Kane
Oct 10 '17 at 14:31
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
add a comment |
The distinction between TO, CC and BCC occurs only in the text headers. At the SMTP level, everybody is a recipient.
TO - There is a TO: header with this recipient's address
CC - There is a CC: header with this recipient's address
BCC - This recipient isn't mentioned in the headers at all, but is still a recipient.
If you have
TO: abc@company.com
CC: xyz@company.com
BCC: boss@company.com
You have three recipients. The headers in the email body will include only the TO: and CC:
add a comment |
Don't add the bcc header.
See this: http://mail.python.org/pipermail/email-sig/2004-September/000151.html
And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from http://pymotw.com/2/smtplib
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
# don't add this, otherwise "to and cc" receivers will know who are the bcc receivers
# + "BCC: %srn" % ",".join(bcc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
add a comment |
You can try MIMEText
msg = MIMEText('text')
msg['to'] =
msg['cc'] =
then send msg.as_string()
http://docs.python.org/library/email-examples.html
4
that example does not use CC
– hoju
Sep 29 '14 at 18:46
1
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
add a comment |
It did not worked for me until i created:
#created cc string
cc = ""someone@domain.com;
#added cc to header
msg['Cc'] = cc
and than added cc in recipient [list] like:
s.sendmail(me, [you,cc], msg.as_string())
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1546367%2fpython-how-to-send-mail-with-to-cc-and-bcc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
6 Answers
6
active
oldest
votes
6 Answers
6
active
oldest
votes
active
oldest
votes
active
oldest
votes
Email headers don't matter to the smtp server. Just add the CC and BCC recipients to the toaddrs when you send your email. For CC, add them to the CC header.
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
1
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
3
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
add a comment |
Email headers don't matter to the smtp server. Just add the CC and BCC recipients to the toaddrs when you send your email. For CC, add them to the CC header.
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
1
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
3
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
add a comment |
Email headers don't matter to the smtp server. Just add the CC and BCC recipients to the toaddrs when you send your email. For CC, add them to the CC header.
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
Email headers don't matter to the smtp server. Just add the CC and BCC recipients to the toaddrs when you send your email. For CC, add them to the CC header.
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
edited Apr 14 '15 at 21:47
answered Oct 9 '09 at 22:52
ABentSpoon
3,86512220
3,86512220
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
1
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
3
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
add a comment |
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
1
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
3
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
smtplib.SMTP does not send lists as to addresses. At least not on python 2.7.2
– LostMohican
Apr 5 '12 at 8:06
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
In this case, the BCC header mentioned in the RFC 2822 does not make any sense.
– Chenxiong Qi
Apr 21 '12 at 9:34
1
1
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
@ABentSpoon a colon is missing after 'Subject'.
– user891260
Jun 25 '12 at 8:04
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
You're right, thanks!
– ABentSpoon
Jun 25 '12 at 19:08
3
3
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
Don't add the bcc header. See this: mail.python.org/pipermail/email-sig/2004-September/000151.html And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from pymotw.com/2/smtplib
– Leonardo Andrade
Apr 14 '15 at 10:45
add a comment |
Key thing is to add the recipients as a list of email ids in your sendmail call.
import smtplib
from email.mime.multipart import MIMEMultipart
me = "user63503@gmail.com"
to = "someone@gmail.com"
cc = "anotherperson@gmail.com,someone@yahoo.com"
bcc = "bccperson1@gmail.com,bccperson2@yahoo.com"
rcpt = cc.split(",") + bcc.split(",") + [to]
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subject"
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
msg.attach(my_msg_body)
server = smtplib.SMTP("localhost") # or your smtp server
server.sendmail(me, rcpt, msg.as_string())
server.quit()
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
2
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
2
Leave themsg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments tosendmail
do that).
– Erica Kane
Oct 10 '17 at 14:31
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
add a comment |
Key thing is to add the recipients as a list of email ids in your sendmail call.
import smtplib
from email.mime.multipart import MIMEMultipart
me = "user63503@gmail.com"
to = "someone@gmail.com"
cc = "anotherperson@gmail.com,someone@yahoo.com"
bcc = "bccperson1@gmail.com,bccperson2@yahoo.com"
rcpt = cc.split(",") + bcc.split(",") + [to]
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subject"
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
msg.attach(my_msg_body)
server = smtplib.SMTP("localhost") # or your smtp server
server.sendmail(me, rcpt, msg.as_string())
server.quit()
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
2
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
2
Leave themsg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments tosendmail
do that).
– Erica Kane
Oct 10 '17 at 14:31
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
add a comment |
Key thing is to add the recipients as a list of email ids in your sendmail call.
import smtplib
from email.mime.multipart import MIMEMultipart
me = "user63503@gmail.com"
to = "someone@gmail.com"
cc = "anotherperson@gmail.com,someone@yahoo.com"
bcc = "bccperson1@gmail.com,bccperson2@yahoo.com"
rcpt = cc.split(",") + bcc.split(",") + [to]
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subject"
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
msg.attach(my_msg_body)
server = smtplib.SMTP("localhost") # or your smtp server
server.sendmail(me, rcpt, msg.as_string())
server.quit()
Key thing is to add the recipients as a list of email ids in your sendmail call.
import smtplib
from email.mime.multipart import MIMEMultipart
me = "user63503@gmail.com"
to = "someone@gmail.com"
cc = "anotherperson@gmail.com,someone@yahoo.com"
bcc = "bccperson1@gmail.com,bccperson2@yahoo.com"
rcpt = cc.split(",") + bcc.split(",") + [to]
msg = MIMEMultipart('alternative')
msg['Subject'] = "my subject"
msg['To'] = to
msg['Cc'] = cc
msg['Bcc'] = bcc
msg.attach(my_msg_body)
server = smtplib.SMTP("localhost") # or your smtp server
server.sendmail(me, rcpt, msg.as_string())
server.quit()
edited Jul 18 '15 at 19:07
answered Apr 29 '15 at 6:57
helios
21125
21125
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
2
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
2
Leave themsg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments tosendmail
do that).
– Erica Kane
Oct 10 '17 at 14:31
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
add a comment |
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
2
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
2
Leave themsg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments tosendmail
do that).
– Erica Kane
Oct 10 '17 at 14:31
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
The bcc field was also requested in this question.
– Steven Bluen
Jul 15 '15 at 18:05
2
2
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
You may add bcc as well in a similar way. I have updated the snippet.
– helios
Jul 18 '15 at 19:01
2
2
Leave the
msg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments to sendmail
do that).– Erica Kane
Oct 10 '17 at 14:31
Leave the
msg['BCC']
off -- it reveals your hidden sender and has no impact on whether the message is sent to them or not (the arguments to sendmail
do that).– Erica Kane
Oct 10 '17 at 14:31
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
You should not add 'Bcc' to the message.
– Julio
Nov 13 '18 at 11:59
add a comment |
The distinction between TO, CC and BCC occurs only in the text headers. At the SMTP level, everybody is a recipient.
TO - There is a TO: header with this recipient's address
CC - There is a CC: header with this recipient's address
BCC - This recipient isn't mentioned in the headers at all, but is still a recipient.
If you have
TO: abc@company.com
CC: xyz@company.com
BCC: boss@company.com
You have three recipients. The headers in the email body will include only the TO: and CC:
add a comment |
The distinction between TO, CC and BCC occurs only in the text headers. At the SMTP level, everybody is a recipient.
TO - There is a TO: header with this recipient's address
CC - There is a CC: header with this recipient's address
BCC - This recipient isn't mentioned in the headers at all, but is still a recipient.
If you have
TO: abc@company.com
CC: xyz@company.com
BCC: boss@company.com
You have three recipients. The headers in the email body will include only the TO: and CC:
add a comment |
The distinction between TO, CC and BCC occurs only in the text headers. At the SMTP level, everybody is a recipient.
TO - There is a TO: header with this recipient's address
CC - There is a CC: header with this recipient's address
BCC - This recipient isn't mentioned in the headers at all, but is still a recipient.
If you have
TO: abc@company.com
CC: xyz@company.com
BCC: boss@company.com
You have three recipients. The headers in the email body will include only the TO: and CC:
The distinction between TO, CC and BCC occurs only in the text headers. At the SMTP level, everybody is a recipient.
TO - There is a TO: header with this recipient's address
CC - There is a CC: header with this recipient's address
BCC - This recipient isn't mentioned in the headers at all, but is still a recipient.
If you have
TO: abc@company.com
CC: xyz@company.com
BCC: boss@company.com
You have three recipients. The headers in the email body will include only the TO: and CC:
answered Oct 9 '09 at 22:41
Jim Garrison
72.3k14120157
72.3k14120157
add a comment |
add a comment |
Don't add the bcc header.
See this: http://mail.python.org/pipermail/email-sig/2004-September/000151.html
And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from http://pymotw.com/2/smtplib
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
# don't add this, otherwise "to and cc" receivers will know who are the bcc receivers
# + "BCC: %srn" % ",".join(bcc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
add a comment |
Don't add the bcc header.
See this: http://mail.python.org/pipermail/email-sig/2004-September/000151.html
And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from http://pymotw.com/2/smtplib
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
# don't add this, otherwise "to and cc" receivers will know who are the bcc receivers
# + "BCC: %srn" % ",".join(bcc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
add a comment |
Don't add the bcc header.
See this: http://mail.python.org/pipermail/email-sig/2004-September/000151.html
And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from http://pymotw.com/2/smtplib
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
# don't add this, otherwise "to and cc" receivers will know who are the bcc receivers
# + "BCC: %srn" % ",".join(bcc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
Don't add the bcc header.
See this: http://mail.python.org/pipermail/email-sig/2004-September/000151.html
And this: """Notice that the second argument to sendmail(), the recipients, is passed as a list. You can include any number of addresses in the list to have the message delivered to each of them in turn. Since the envelope information is separate from the message headers, you can even BCC someone by including them in the method argument but not in the message header.""" from http://pymotw.com/2/smtplib
toaddr = 'buffy@sunnydale.k12.ca.us'
cc = ['alexander@sunydale.k12.ca.us','willow@sunnydale.k12.ca.us']
bcc = ['chairman@slayerscouncil.uk']
fromaddr = 'giles@sunnydale.k12.ca.us'
message_subject = "disturbance in sector 7"
message_text = "Three are dead in an attack in the sewers below sector 7."
message = "From: %srn" % fromaddr
+ "To: %srn" % toaddr
+ "CC: %srn" % ",".join(cc)
# don't add this, otherwise "to and cc" receivers will know who are the bcc receivers
# + "BCC: %srn" % ",".join(bcc)
+ "Subject: %srn" % message_subject
+ "rn"
+ message_text
toaddrs = [toaddr] + cc + bcc
server = smtplib.SMTP('smtp.sunnydale.k12.ca.us')
server.set_debuglevel(1)
server.sendmail(fromaddr, toaddrs, message)
server.quit()
answered Apr 14 '15 at 12:17
Leonardo Andrade
85811122
85811122
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
add a comment |
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
Thumbs up for flair :D
– Chris
Jun 28 '17 at 8:48
add a comment |
You can try MIMEText
msg = MIMEText('text')
msg['to'] =
msg['cc'] =
then send msg.as_string()
http://docs.python.org/library/email-examples.html
4
that example does not use CC
– hoju
Sep 29 '14 at 18:46
1
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
add a comment |
You can try MIMEText
msg = MIMEText('text')
msg['to'] =
msg['cc'] =
then send msg.as_string()
http://docs.python.org/library/email-examples.html
4
that example does not use CC
– hoju
Sep 29 '14 at 18:46
1
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
add a comment |
You can try MIMEText
msg = MIMEText('text')
msg['to'] =
msg['cc'] =
then send msg.as_string()
http://docs.python.org/library/email-examples.html
You can try MIMEText
msg = MIMEText('text')
msg['to'] =
msg['cc'] =
then send msg.as_string()
http://docs.python.org/library/email-examples.html
answered Oct 9 '09 at 22:42
foosion
3,198134988
3,198134988
4
that example does not use CC
– hoju
Sep 29 '14 at 18:46
1
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
add a comment |
4
that example does not use CC
– hoju
Sep 29 '14 at 18:46
1
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
4
4
that example does not use CC
– hoju
Sep 29 '14 at 18:46
that example does not use CC
– hoju
Sep 29 '14 at 18:46
1
1
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
I agree that the examples on the above link do not treat Bcc. This is what @hoju probably meant.
– shailenTJ
Aug 13 '15 at 10:21
add a comment |
It did not worked for me until i created:
#created cc string
cc = ""someone@domain.com;
#added cc to header
msg['Cc'] = cc
and than added cc in recipient [list] like:
s.sendmail(me, [you,cc], msg.as_string())
add a comment |
It did not worked for me until i created:
#created cc string
cc = ""someone@domain.com;
#added cc to header
msg['Cc'] = cc
and than added cc in recipient [list] like:
s.sendmail(me, [you,cc], msg.as_string())
add a comment |
It did not worked for me until i created:
#created cc string
cc = ""someone@domain.com;
#added cc to header
msg['Cc'] = cc
and than added cc in recipient [list] like:
s.sendmail(me, [you,cc], msg.as_string())
It did not worked for me until i created:
#created cc string
cc = ""someone@domain.com;
#added cc to header
msg['Cc'] = cc
and than added cc in recipient [list] like:
s.sendmail(me, [you,cc], msg.as_string())
answered Jan 13 '17 at 9:47
marko_b123
959
959
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f1546367%2fpython-how-to-send-mail-with-to-cc-and-bcc%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown