I am learning to send email in python and am encountering several problems. One of them is already in importing the smtplib module. My code is as follows:
from smtplib import SMTP
smtp=SMTP('smtp.live.com',587)
smtp.starttls()
smtp.login('[email protected]','senha')
msg='ola mundo'
smtp.sendmail('[email protected]',['[email protected]'],msg)
smtp.quit()
This script generates the following error:
Traceback (most recent call last):
File "C:\Users\Benedito\Desktop\email.py", line 1, in <module>
from smtplib import SMTP
File "C:\Users\Benedito\AppData\Local\Programs\Python\Python35- 32\lib\smtplib.py", line 47, in <module>
import email.utils
File "C:\Users\Benedito\Desktop\email.py", line 1, in <module>
from smtplib import SMTP
ImportError: cannot import name 'SMTP'
From what I understand, the error treats the smtplib module as if it did not have the SMTP method on it. However, when I perform direct import on the Python command line, this import error does not occur. Why is giving error when I run a script and is not giving error when I execute writing line by line in the python command line?
I'm on Windows 8 and use Python 3.5.2