<br><br><div><span class="gmail_quote">On 20 Feb 2006 01:01:38 -0800, <b class="gmail_sendername"><a href="mailto:eight02645999@yahoo.com">eight02645999@yahoo.com</a></b> <<a href="mailto:eight02645999@yahoo.com">eight02645999@yahoo.com
</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">hi<br>i currently am using this email function that can send single email
<br>address<br>[SNIP]<br>was wondering how to modify the code so as i can send to multiple email<br>recipients using "TO"? thanks.<br></blockquote></div><br><br>
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 :)<br>
<br>
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.<br>
<br>
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.<br>
<br>
-----------------------------<br>
<br>
SENDER = "<a href="mailto:you@mydom1.com">you@mydom1.com</a>"<br>
RECIPS = ["<a href="mailto:joe@mydom2.com">joe@mydom2.com</a>","<a href="mailto:support@mydom3.com">support@mydom3.com</a>","<a href="mailto:sales@mydom4.com">sales@mydom4.com</a>"]<br>
FROM = ' "<a href="mailto:you@mydom1.com">you@mydom1.com</a>" <<a href="mailto:you@mydom1.com">you@mydom1.com</a>> '<br>
TO = " Undisclosed recipients "<br>
CC = " Uknown recipients "<br>
<br>
def email(HOST,SENDER, RECIPIENTS, FROM,TO,SUBJECT ,BODY,CC=None):<br>
<div id="mb_0"> import smtplib<br> import string, sys<br> body = string.join((<br> "From: %s" % FROM,<br> "To: %s" % TO,<br> "Subject: %s" % SUBJECT,<br> "CC: %s" % CC,
<br> "",<br> BODY), "\r\n")<br><br> server = smtplib.SMTP(HOST)<br> failed = server.sendmail(SENDER, RECIPIENTS,body)<br> server.quit()</div>
<br>
----------------------------<br>
<br>
HTH :)<br clear="all"><br>-- <br><br>Tim Williams