By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,846 Members | 1,857 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,846 IT Pros & Developers. It's quick & easy.

do cc list from smtplib

P: n/a
hi
i have email code:

def email(HOST,FROM,TO,SUBJECT,BODY):
import smtplib
import string, sys
body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO],body)
server.quit()
is there a way to include CC list for the smtplib module?
thanks

Oct 21 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On 21 Oct 2005 02:34:40 -0700, ei***********@yahoo.com
<ei***********@yahoo.com>

def email(HOST,FROM,TO,CC,SUBJECT,BODY):
import smtplib
import string, sys body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"CC: %s % CC,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO]+[CC],body)
server.quit()

Oct 21 '05 #2

P: n/a
Tim Williams (gmail) wrote:
On 21 Oct 2005 02:34:40 -0700, ei***********@yahoo.com
<ei***********@yahoo.com>
def email(HOST,FROM,TO,CC,SUBJECT,BODY):
import smtplib
import string, sys


body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"CC: %s % CC,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO]+[CC],body)
server.quit()


Assuming that TO and CC are single addresses it would be saner to use:

server.sendmail(FROM, [TO, CC], body)

- in other words, use a two-element list rather than creating it by
concatenating two one-element lists!

Note that as far as the SMTP protocol is concerned it's the list of
recipients that gets actions, not the headers in the message.

stating-the-obvious-ly y'rs - steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/
Oct 21 '05 #3

P: n/a
Tim Williams (gmail) wrote:
On 21 Oct 2005 02:34:40 -0700, ei***********@yahoo.com
<ei***********@yahoo.com>
def email(HOST,FROM,TO,CC,SUBJECT,BODY):
import smtplib
import string, sys


body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"CC: %s % CC,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO]+[CC],body)
server.quit()


Assuming that TO and CC are single addresses it would be saner to use:

server.sendmail(FROM, [TO, CC], body)

- in other words, use a two-element list rather than creating it by
concatenating two one-element lists!

Note that as far as the SMTP protocol is concerned it's the list of
recipients that gets actions, not the headers in the message.

stating-the-obvious-ly y'rs - steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC www.holdenweb.com
PyCon TX 2006 www.python.org/pycon/

Oct 21 '05 #4

P: n/a
On 21/10/05, Steve Holden <st***@holdenweb.com> wrote:

Assuming that TO and CC are single addresses it would be saner to use:

:)

Assuming that the envelope TOs (inc CCs) are the same as the
Header-TOs and Header-CCs

Actually, I think this would be safer !
def email(HOST,FROM,TO,CC, RECIPS, SUBJECT,BODY):

...
...
...
server.sendmail(FROM,RECIPS,body)

RECIPS = list of SMTP recipients
TO & CC = Text representation of some/all/none of the SMTP recipients
and/or other text

RECIPS should be either a single address as a string *or* a list
containing 1 or more addresses
Oct 21 '05 #5

P: n/a

Tim Williams (gmail) wrote:
On 21 Oct 2005 02:34:40 -0700, ei***********@yahoo.com
<ei***********@yahoo.com>

def email(HOST,FROM,TO,CC,SUBJECT,BODY):
import smtplib
import string, sys

body = string.join((
"From: %s" % FROM,
"To: %s" % TO,
"CC: %s % CC,
"Subject: %s" % SUBJECT,
"",
BODY), "\r\n")

print body

server = smtplib.SMTP(HOST)
server.sendmail(FROM, [TO]+[CC],body)
server.quit()


Oct 21 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.