Reputation: 2660
I am trying to send an email with python and getting errors. Here is my code:
import smtplib
server = smtplib.SMTP('smtp.gmail.com', 465)
server.login("[email protected]", "pass")
msg = "Hello!"
server.sendmail("[email protected]", "[email protected]", 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?
Upvotes: 3
Views: 1006
Reputation: 109546
In email.py
, the import should be:
from email.mime.multipart import smtplib
Or possibly:
import smtplib
from email.mime.multipart import [...]
Upvotes: 2
Reputation: 94483
You have a script C:/Users/Kevin/Desktop/Python\email.py
that shadows email package from stdlib. Rename your script.
In the future avoid script names that are already taken by stdlib. Especially avoid test.py! :-)
Upvotes: 2
Reputation: 6189
Your 'import smtplib' statement is correct.
Please double check the source code that you are sharing, as I dont see the ' import smtplib from email.mime.multipart'anywhere in your source.
Typical way of implementing the email sending logic in python can be found here . and the library doc here
Upvotes: 2