当我尝试安装 easy_install 电子邮件时,如何解决没有名为 'email.MIMEMultipart' 的模块?
How to solve No module named 'email.MIMEMultipart', when I have tried installing easy_install email?
This is the simple email sending code I have copied from a source and trying to learn it. But this is giving error even after I have installed easy_install email. Below is the code :
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def sendmail (from_email, password, to_email, subject, message):
msg=MIMEMultipart()
msg['From']= from_email
msg['To']= to_email
msg['Subject']= subject
msg.attach(MIMEText(message, 'plain'))
try:
server= smtplib.SMTP_SSL('smtp.office365.com', 465)
server.echo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close()
return True
except Exception as e:
print('Something went wrong '+str())
return False
Traceback (most recent call last):
File "C:\Users\RYadav\PycharmProjects\MAPILab\rough work.py", line 1, in <module>
import smtplib
File "C:\Users\RYadav\PycharmProjects\MAPILab\smtplib.py", line 2, in <module>
from email.MIMEMultipart import MIMEMultipart
ModuleNotFoundError: No module named 'email.MIMEMultipart'
Process finished with exit code 1
使用这个命令:
从 email.mime.multipart 导入 MIMEMultipart
从 email.mime.text 导入 MIMEText
检查此留置权 = https://docs.python.org/3/library/email.mime.html#module-email.mime
This is the simple email sending code I have copied from a source and trying to learn it. But this is giving error even after I have installed easy_install email. Below is the code :
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
def sendmail (from_email, password, to_email, subject, message):
msg=MIMEMultipart()
msg['From']= from_email
msg['To']= to_email
msg['Subject']= subject
msg.attach(MIMEText(message, 'plain'))
try:
server= smtplib.SMTP_SSL('smtp.office365.com', 465)
server.echo()
server.login(from_email, password)
server.sendmail(from_email, to_email, msg.as_string())
server.close()
return True
except Exception as e:
print('Something went wrong '+str())
return False
Traceback (most recent call last):
File "C:\Users\RYadav\PycharmProjects\MAPILab\rough work.py", line 1, in <module>
import smtplib
File "C:\Users\RYadav\PycharmProjects\MAPILab\smtplib.py", line 2, in <module>
from email.MIMEMultipart import MIMEMultipart
ModuleNotFoundError: No module named 'email.MIMEMultipart'
Process finished with exit code 1
使用这个命令:
从 email.mime.multipart 导入 MIMEMultipart
从 email.mime.text 导入 MIMEText
检查此留置权 = https://docs.python.org/3/library/email.mime.html#module-email.mime