我有這段代碼,因爲我正在嘗試使用Python發送電子郵件。無法用Python發送電子郵件
def Mail():
import smtplib
import textwrap
SERVER = "localhost"
FROM = "fromemail"
TO = ["toemail"]
SUBJECT =(input('What is the subject of your E-Mail'))
TEXT =(input('What do you want the E-Mail to say?'))
message = textwrap.dedent("""\
From: %s
To: %s
Subject: %s
%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT))
server = smtplib.SMTP(SERVER)
server.sendmail(FROM, TO, message)
server.quit()
這是我得到的錯誤消息。
Traceback (most recent call last):
File "<pyshell#0>", line 1, in <module>
Mail()
File "E:\Coursework\EMail.py", line 26, in Mail
server = smtplib.SMTP(SERVER)
File "C:\Python33\python-3.3.5\lib\smtplib.py", line 241, in __init__
(code, msg) = self.connect(host, port)
File "C:\Python33\python-3.3.5\lib\smtplib.py", line 322, in connect
(code, msg) = self.getreply()
File "C:\Python33\python-3.3.5\lib\smtplib.py", line 375, in getreply
raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
是您的計算機上運行的郵件服務器(可能是'smtpd'或'sendmail')嗎?如果沒有,那會解釋你的錯誤,因爲在localhost上沒有任何連接。 –
您是否使用'telnet localhost 25'獲得SMTP問候消息? [翻譯:它是python的錯嗎?] – AnFi
如何知道郵件服務器是否正在運行?我有能力發送/檢索電子郵件。 – jackfromperu