do cc list from smtplib

E

eight02645999

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
 
T

Tim Williams (gmail)

On 21 Oct 2005 02:34:40 -0700, (e-mail address removed)
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()
 
S

Steve Holden

Tim said:
On 21 Oct 2005 02:34:40 -0700, (e-mail address removed)
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
 
S

Steve Holden

Tim said:
On 21 Oct 2005 02:34:40 -0700, (e-mail address removed)
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
 
T

Tim Williams (gmail)

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
 
B

Bean

Tim said:
On 21 Oct 2005 02:34:40 -0700, (e-mail address removed)
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()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,070
Latest member
BiogenixGummies

Latest Threads

Top