这是我从来源复制并尝试学习的简单电子邮件发送代码。但即使我安装了 easy_install 电子邮件,这也会出错。下面是代码:
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