tags:

views:

197

answers:

2
import smtplib

SERVER = "localhost"

FROM = "[email protected]"
TO = ["[email protected]"]

SUBJECT = "Hello!"

TEXT = "This message was sent with Python's smtplib."
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()

This is giving the error:

'**The debugged program raised the exception unhandled AttributeError
"'module' object has no attribute 'SMTP'"
File: /home/an/Desktop/email.py, Line: 13**'
+8  A: 

Rename your file to something other than email.py. Also get rid of any email.pyc file left over. Problem solved.

apphacker
It indeed fixes the problem... But what was the source of it?
Joce
+3  A: 

This happens because email is a built-in library that comes standard with python. See: http://docs.python.org/library/email. If you rename your program to something else (as suggested above), that should do the trick.

Niranjan Tulpule
I didn't realize Python's namespacing was /that/ poor.
Matthew Flaschen
it's not a namespace, it is a library. The same thing would happen if you put your own system32.dll or whatever in your exe directory. it's looking for email.py and it just happened to find it in the source directory rather than the python libs directory.
SpliFF
What do you mean, 'poor'? This is an absolute killer feature of Python - the ability to override whatever you like, whenever you like. Python's philosophy is 'we're all consenting adults here', and allows you to do what you like.
Daniel Roseman