On 20 Feb 2006 01:01:38 -0800, [EMAIL PROTECTED] <[EMAIL PROTECTED] > wrote:
hi
i currently am using this email function that can send single email
address
[SNIP]
was wondering how to modify the code so as i can send to multiple email
recipients using "TO"? thanks.


You are making the common mistake of thinking that the header sender and  recipients are the same as the SMTP-envelope sender and recipients,   in reality they do not have to bear any similarity or relationship :)

You need a single list containing all the recipients by email address,  and strings containing the text representations of the header From, To and Cc fields.

There is a module called email,  so beware of calling your function the same name.  Also,  you may find the email module becomes helpful for building emails as your function/requirements get more complex.

-----------------------------

SENDER = "[EMAIL PROTECTED]"
RECIPS =  ["[EMAIL PROTECTED]","[EMAIL PROTECTED]","[EMAIL PROTECTED]"]
FROM = '  "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> '
TO = " Undisclosed recipients "
CC = " Uknown recipients "

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

   server = smtplib.SMTP(HOST)
   failed =  server.sendmail(SENDER, RECIPIENTS,body)
   server.quit()

----------------------------

HTH :)

--

Tim Williams
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to