smtplib --> receiving emails two times

Toralf Wittner wittner at fossilverlag.de
Thu Jan 25 08:41:54 EST 2001


Hi Python coders,

I try to collect data from a HTML formular via cgi and email the stuff to a 
certain address. The script is as follows:


#!/usr/bin/env python

import cgi, smtplib
print "Content-Type: text/plain\n"

form = cgi.FieldStorage()
keyList = form.keys()
keyList.sort()

fromaddress = toaddress = "given_email_address"
msg = ("From: %s\r\nTo: %s\r\nSubject: topic\r\n\r\n" % (fromaddress, 
toaddress))
for i in keyList:
        msg = msg + "%s ____________________ %s\n" % (i, form[i].value)

server = smtplib.SMTP('given_server_name ')
server.sendmail(fromaddress, toaddress, msg)
server.quit()


This works basically, however all emails are received two times wich is 
annoying at least . I can't see why this happens (the given example in the 
smtplib reference is almost identical to the one above). Also note that 
using a script like the following gives me exactly one email.


#!/usr/bin/env python

import smtplib

fromaddress = toaddress = 'given_email_address'
msg = ("From: %s\r\nTo: %s\r\n\r\n" % (fromaddress, toaddress))
msg = msg + "additional_text"
server = smtplib.SMTP('given_server_name')
server.set_debuglevel(1)
server.sendmail(fromaddress, toaddress, msg)
server.quit()


(I'm using Python 2.0)

I appreciate any help concerning this problem. Thank you!
Kind regards,
Toralf Wittner




More information about the Python-list mailing list