smtplib --> receiving emails two times

Martin Franklin martin.franklin at westerngeco.com
Thu Jan 25 09:19:33 EST 2001


Toralf,

You have the To: line in the message body.  This gets  used by the smtp 
server to send the mail twice
so change the following.
                      
msg = ("From: %s\r\nTo: %s\r\nSubject: topic\r\n\r\n"
%(fromaddress,toaddress))


to 

msg = ("From: %s\r\nSubject: topic\r\n\r\n" %(fromaddress))

Martin

Toralf Wittner wrote:
> 
> 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
> 
> --
> http://mail.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list