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**' 
2
  • Which version of Python is this? Commented May 19, 2009 at 6:12
  • 3
    Could you get rid of the community wiki. Heh. Commented May 19, 2009 at 6:24

2 Answers 2

12

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

Sign up to request clarification or add additional context in comments.

2 Comments

It indeed fixes the problem... But what was the source of it?
email is a module in the standard python library that is used by smtplib. Your file was named "email.py": Your module "email" replaced the standard module of python (because after it in PYTHONPATH)
5

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

3 Comments

I didn't realize Python's namespacing was /that/ poor.
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.
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.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.