# Lesson 14 email

**URL:** https://forum.codewithmosh.com/t/lesson-14-email/9983
**Category:** Python
**Created:** [January 15, 2022, 5:00pm UTC](https://forum.codewithmosh.com/t/lesson-14-email/9983 "2022-01-15T17:00:33Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![convurtapp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/convurtapp/32/2875_2.png) [@convurtapp](https://forum.codewithmosh.com/u/convurtapp)
#### Post date: [January 15, 2022, 5:00pm UTC](https://forum.codewithmosh.com/t/lesson-14-email/9983/1 "2022-01-15T17:00:33Z")

</div>

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

---

<div class="post-metadata">

### Author: ![convurtapp](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/convurtapp/32/2875_2.png) [@convurtapp](https://forum.codewithmosh.com/u/convurtapp)
#### Post date: [January 16, 2022, 7:35pm UTC](https://forum.codewithmosh.com/t/lesson-14-email/9983/2 "2022-01-16T19:35:43Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![phildude](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@phildude](https://forum.codewithmosh.com/u/phildude)
#### Post date: [May 6, 2022, 11:52am UTC](https://forum.codewithmosh.com/t/lesson-14-email/9983/3 "2022-05-06T11:52:13Z")

</div>

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](mailto:phildudex@gmail.com)”  
message[“subject”] = “This is a test”  
message.attach(MIMEText(“Body”))

with smtplib.SMTP(host=“[smtp.gmail.com](http://smtp.gmail.com)”, port=587) as smtp:  
smtp.ehlo()  
smtp.starttls()  
smtp.login(“[philipawoseyila@gmail.com](mailto:philipawoseyila@gmail.com)”, “blahblahblah”)  
smtp.send\_message(message)  
print(“sent…”)

---

<div class="post-metadata">

### Author: ![Tugrul](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/tugrul/32/6733_2.png) [@Tugrul](https://forum.codewithmosh.com/u/Tugrul)
#### Post date: [July 27, 2023, 5:48pm UTC](https://forum.codewithmosh.com/t/lesson-14-email/9983/4 "2023-07-27T17:48:09Z")

</div>

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](mailto: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](https://support.google.com/mail/?p=InvalidSecondFactor) qc8-20020a170906d8a800b00989828a42e8sm1012488ejb.154 - gsmtp’)

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

---

<div class="post-metadata">

### Author: ![Tugrul](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/tugrul/32/6733_2.png) [@Tugrul](https://forum.codewithmosh.com/u/Tugrul)
#### Post date: [July 28, 2023, 4:12pm UTC](https://forum.codewithmosh.com/t/lesson-14-email/9983/5 "2023-07-28T16:12:21Z")

</div>

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.
