Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting the error: No module named 'email.MIMEMultipart'?

I'm trying to experiment with simple code to send an email from a Python script. I keep getting an error that the module 'email.MIMEMultipart' does not exist. To simplify the question/answer process, I can narrow it down even further. From the Python environment prompt I can enter

>>>import email

>>> dir(email)

It will list a bunch of modules in the email module, but none of the MIME modules are there. I can see them from WindowsExplorer in the same lib folder as all the other modules. After searching other questions I did see that I had named my test program 'email.py' which I see now is a big no-no. I deleted it and verified there isn't also an 'email.pyc'.

I'm using Windows 10, Python 3.5.2. I've also already reinstalled Python with no improvement.

Can anyone tell me what else I should check? This is the actual code:

 import smtplib
 from email.MIMEMultipart import MIMEMultipart
like image 879
daavidm Avatar asked Sep 16 '16 23:09

daavidm


1 Answers

from email.MIMEMultipart import MIMEMultipart

Is the correct import for Python 2.x.

According to the Python 3 examples in the documentation (email), you need:

from email.mime.multipart import MIMEMultipart
like image 158
TessellatingHeckler Avatar answered Oct 31 '22 18:10

TessellatingHeckler