此代码“假设”发送电子邮件。
import smtplib
#SERVER = "localhost"
FROM = '[email protected]'
TO = ["[email protected]"] # must be a list
SUBJECT = "Hello!"
TEXT = "This message was sent with Python's smtplib."
# Prepare actual message
message = """\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
# Send the mail
server = smtplib.SMTP('myserver')
server.sendmail(FROM, TO, message)
server.quit()
我收到此错误消息。
Traceback (most recent call last):
File "C:\Users\myCpu\Documents\myFiles\python\test wy.py", line 1, in <module>
import smtplib
File "C:\Python27\lib\smtplib.py", line 46, in <module>
import email.utils
File "C:/Users/myCpu/Documents/myFiles/python\email.py", line 5, in <module>
ImportError: No module named mime.text
使用:
python 2.7
Windows 7 专业版
Gmail (@gmail.com)
谁能帮我这个代码?
最佳答案
将您正在处理的名为 email.py 的文件重命名为其他名称。它可能会破坏您的库中的导入。
关于python - 出现错误 `No module named mime.text` [Python],我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/40434313/