此代碼是「假設」發送電子郵件。獲取錯誤`No module named mime.text` [Python]
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的Professionnal
的Gmail(@ gmail.com)
誰能幫我個是代碼?
這是我得到的:'server = smtplib.SMTP('myserver') 文件「C:\ Python27 \ lib \ smtplib.py」,第256行,在__init__中 (code,msg)= self。連接(主機,端口) 文件「C:\ Python27 \ lib \ smtplib.py」,行316,連接 self.sock = self._get_socket(host,port,self.timeout) 文件「C:\ Python27 \ lib \ smtplib.py「,第291行,在_get_socket 返回socket.create_connection((主機,端口),超時) 文件」C:\ Python27 \ lib \ socket.py「,第557行,在create_connection中 在getaddrinfo(主機,端口,0,SOCK_STREAM)中: gaierror:[Errno 11004] getaddrinfo失敗' –