sending mailing list with smtplib

3KWA eugene at boardkulture.com
Mon Aug 14 09:22:26 EDT 2006


Hi all,

I tried to send a small mailing list using python today (2036 emails).
For that purpose I looked in the doc for some code examples (I had
never done it before). And I ended up writing and running this little
script:

# list.txt is a text file container an email per line
fp=open('list.txt','r')
list=fp.readlines()
fp.close()

# message.txt is the plaine text message to send
textfile='message.txt'
subject='[xsbar] alive and kicking'
me='eugene at xsbar.com'

# rom and example in the doc
import smtplib

from email.MIMEText import MIMEText

fp = open(textfile, 'rb')
msg = MIMEText(fp.read())
fp.close()

# ... but the actual message sending in a loop to send one email each
(didn't work)
for line in list:
    you=line[:-1]
    msg['Subject'] = subject
    msg['From'] = me
    msg['To'] = you

    s = smtplib.SMTP()
    s.connect()
    s.sendmail(me, [you], msg.as_string())
    s.close()

but it copied all the recipients in the header (To:) which I don't
understand?

Can someone help me understand what I did wrong?

Thanks,

EuGeNe




More information about the Python-list mailing list