Lesson 14 email

I am getting this error message when I try and send email with the lesson 14 example. Any ideas why? Im Python 3.7 with Pycharm CE

No module named ‘email.mime’; ‘email’ is not a package.

This is the example in the lesson:
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

I figured this one out in case anyone else makes a rookie mistake like me. I was naming my files so I could go back and review them when I started building something real, so I had named the email lesson email.py. I guess by naming the file that, I broke how the default import worked. I did the same thing with datetime as well, which is how I figured it out.

I am using Vscode, and I got an error also, I am using app.py just like Mosh. I got the same error with the next topic which is templates.

this is my code below

from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib

message = MIMEMultipart()
message[“from”] = “Philip Awo”
message[“to”] = “phildudex@gmail.com
message[“subject”] = “This is a test”
message.attach(MIMEText(“Body”))

with smtplib.SMTP(host=“smtp.gmail.com”, port=587) as smtp:
smtp.ehlo()
smtp.starttls()
smtp.login(“philipawoseyila@gmail.com”, “blahblahblah”)
smtp.send_message(message)
print(“sent…”)

Hey, i have the same problem.

In my case, i get the error with the login methode:

Traceback (most recent call last):
File “c:\Dev\Programming\Python\Complete Python Mastery\8. Library.py”, line 296, in
smtp.login(“tugrularslan1987@gmail.com”, “hamburgistanbul”)
File “C:\Users\Tugrul\AppData\Local\Programs\Python\Python311\Lib\smtplib.py”, line 750, in login
raise last_exception
File “C:\Users\Tugrul\AppData\Local\Programs\Python\Python311\Lib\smtplib.py”, line 739, in login
(code, resp) = self.auth(
^^^^^^^^^^
File “C:\Users\Tugrul\AppData\Local\Programs\Python\Python311\Lib\smtplib.py”, line 662, in auth
raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (534, b’5.7.9 Application-specific password required. Learn more at\n5.7.9 Sign in with app passwords - Google Account Help qc8-20020a170906d8a800b00989828a42e8sm1012488ejb.154 - gsmtp’)

I used the same credential to login via gmail account.
Have anyone a solution for that?

I think i found the problem. I have activity in my google mail prvoder the 2-factor authefication. And therefore is my python script run to an error. I try just then with my another email provider(strato) and it’s work. Maybe, anyone have a soulution with the google provider and the 2-f-autenification

Thanks.

1 Like