I have a script that results in an email being sent out with smtplib.SMTP python module.

When I run it from within IDLE is sends fine with no error messages. I am trying various ways to automate it with crontab to go everyday at 10am.

If I run it from terminal, I get an error:

$ python endofmonth.py
Traceback (most recent call last):
  File "endofmonth.py", line 74, in <module>
AttributeError: SMTP instance has no attribute 'send_message'

Why would it work in IDLE but not when called from terminal?


The send_message method to SMTP class was added in Python 3.2. You are calling the script to be run using python which is a symlink for Python 2. Since send_message method is not defined in Python 2, you get an AttributeError.

To get over this, you need to call your script using Python 3.2 or newer. Run it as:

python3 endofmonth.py

and it would work.

You are most probably using the Python 3 version of IDLE which is the reason it works there.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.