multiple email recipients
Tim Williams (gmail)
tdwdotnet at gmail.com
Mon Feb 20 05:23:27 EST 2006
On 20 Feb 2006 01:01:38 -0800, eight02645999 at yahoo.com <
eight02645999 at yahoo.com> 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 = "you at mydom1.com"
RECIPS = ["joe at mydom2.com","support at mydom3.com","sales at mydom4.com"]
FROM = ' "you at mydom1.com" <you at mydom1.com> '
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060220/970d604e/attachment.html>
More information about the Python-list
mailing list