Sending email from python and the error keeps popping up
I am trying to send email with Python and am getting errors. Here is my code:
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 465)
server.login("someone@gmail.com", "pass")
msg = "Hello!"
server.sendmail("someone@gmail.com", "someone@gmail.com", msg)
print("Sent")
This is the error I keep getting
Traceback (most recent call last):
File "C:/Users/me/Desktop/Python/email65.py", line 1, in <module>
import smtplib
File "C:\Users\me\AppData\Local\Programs\Python\Python36-32\lib\smtplib.py", line 47, in <module>
import email.utils
File "C:/Users/me/Desktop/Python\email.py", line 1
import smtplib from email.mime.multipart
^
SyntaxError: invalid syntax'
What am I doing wrong?
You have a script C:/Users/Kevin/Desktop/Python\email.py
that hides the email package from stdlib. Rename your script.
In the future, avoid script names that are already accepted by stdlib. Especially avoid test.py ! :-)
The email.py
import should contain:
from email.mime.multipart import smtplib
Or perhaps:
import smtplib
from email.mime.multipart import [...]
Your import smtplib statement is correct.
Please double check the source you are using as I do not see the "import of smtplib from email.mime.multipart'anywhere" in your source.
A typical way to implement email sending logic in python can be found here . and doc library here