出现错误“没有名为 mime.text 的模块”[Python]
Getting error `No module named mime.text` [Python]
此代码是 "suppose" 发送电子邮件。
import smtplib
#SERVER = "localhost"
FROM = 'myEmail@email.com'
TO = ["toEmail@email.com"] # 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)
谁能帮我写下这段代码?
这就是我为 gmail 所做的。
希望这能解决您的问题
from email.mime.text import MIMEText
def construct_mesage():
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string())}
将您正在处理的名为 email.py 的文件重命名为其他名称。它可能会破坏您库中的导入。
此代码是 "suppose" 发送电子邮件。
import smtplib
#SERVER = "localhost"
FROM = 'myEmail@email.com'
TO = ["toEmail@email.com"] # 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)
谁能帮我写下这段代码?
这就是我为 gmail 所做的。 希望这能解决您的问题
from email.mime.text import MIMEText
def construct_mesage():
message = MIMEText(message_text)
message['to'] = to
message['from'] = sender
message['subject'] = subject
return {'raw': base64.urlsafe_b64encode(message.as_string())}
将您正在处理的名为 email.py 的文件重命名为其他名称。它可能会破坏您库中的导入。