Server.sendmail with no "to_addrs" parameter.

Tim Williams (gmail) tdwdotnet at gmail.com
Wed Mar 22 12:31:02 CET 2006


On 22 Mar 2006 03:18:41 -0800, EdWhyatt <ed.whyatt at gmail.com> wrote:
>
> Hi all, I have searched the group with no answer to this particular
> problem.
>
> In my sendmail program, I would like to have the ability to send a mail
> message with no-one email address in the To field.
>
> I do this by adding the mail to the CC field via a header. However, by
> the time I get to the point of sending the mail, my recipient list is
> now empty, so I get the "SMTPRecipientsRefused" error.


 You are making the common mistake of thinking that the header recipients
are the same as the SMTP-envelope 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.



-----------------------------
HOST = '127.0.0.1'
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 = " none at mydomain.local "
CC = " Uknown recipients "

 def send_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)
   server.sendmail(SENDER, RECIPIENTS,body)
   server.quit()

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

HTH :)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20060322/47709cc8/attachment.html>


More information about the Python-list mailing list