-1

Please help me I want to create an AI which can send emails using python but when I run my code it says:

Traceback (most recent call last):
  File "c:\Users\zigzag\Desktop\email.py", line 1, in <module>
    import smtplib
  File "B:\Python36\lib\smtplib.py", line 47, in <module>
    import email.utils
  File "c:\Users\zigzag\Desktop\email.py", line 3, in <module>
    mail = smtplib.SMTP('smtp.gmail.com', 587)
AttributeError: module 'smtplib' has no attribute 'SMTP'

here is my code:

import smtplib

mail = smtplib.SMTP('smtp.gmail.com', 587)
mail.starttls()
mail.login('myemail@myemail.com', 'mypassword')
mail.sendmail('myemail@myemail.com', 'anotheremail@anotheremail.com', "<h1 style = \"color:rgb(121, 21, 321)\">Hello World</h1>")
mail.close()
  • 1
    Possible duplicate of [No attribute 'SMTP', error when trying to send email in Python](https://stackoverflow.com/questions/16512256/no-attribute-smtp-error-when-trying-to-send-email-in-python) – wpercy Aug 03 '18 at 15:11
  • Just rename your script to something other than `email.py` and it should work fine. – wpercy Aug 03 '18 at 15:11
  • I renamed the file now there is another error: –  Aug 03 '18 at 15:45

1 Answers1

0

You should change the name of your .py script (email.py) to some different name.

  • This is the answer. Python is weird, the same thing happens when you name a python file `tkinter.py` and try to edit it with IDLE, it will not run and make a __pycache__ folder. – Remigiusz Schoida Aug 03 '18 at 15:18