python电子邮件 - 简单的示例运行没有错误,但电子邮件永远不会到达

jon*_*omo 3 python email smtp smtpd

我复制并粘贴了这个例子并填写了我自己的电子邮件地址.

# Import smtplib for the actual sending function
import smtplib

# Import the email modules we'll need
from email.mime.text import MIMEText

# Open a plain text file for reading.  For this example, assume that
# the text file contains only ASCII characters.
fp = open('/Users/Jon/dev/iit/test-tools/logs/practice_tests.test_one.log', 'rb')
# Create a text/plain message
msg = MIMEText(fp.read())
fp.close()

me = 'Jon@MacBookPro.com'
you = 'jon.drowell@yahoo.com'

# me == the sender's email address
# you == the recipient's email address
msg['Subject'] = 'The contents of the log file'
msg['From'] = me
msg['To'] = you

# Send the message via our own SMTP server, but don't include the
# envelope header.
s = smtplib.SMTP('localhost', 1025)
s.sendmail(me, [you], msg.as_string())
s.quit()
Run Code Online (Sandbox Code Playgroud)

然后我打开另一个终端窗口并运行以下命令:

python -m smtpd -n -c DebuggingServer localhost:1025
Run Code Online (Sandbox Code Playgroud)

当我运行文件发送电子邮件时,它完成没有错误,并且运行该python -m smtpd -n -c DebuggingServer localhost:1025命令的终端打印一个看起来正确的好消息:

---------- MESSAGE FOLLOWS ----------
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Subject: The contents of the log file
From: Jon@MacBookPro.com
To: jon.crowell@yahoo.com
X-Peer: 127.0.0.1

line one
line two
line three
------------ END MESSAGE ------------
Run Code Online (Sandbox Code Playgroud)

但是,当我查看我的雅虎电子邮件地址时,电子邮件永远不会到达.我等了大约5分钟,我觉得这已经足够了.我做错了什么?

Die*_*sch 5

来自smtpd文档

class smtpd.DebuggingServer(localaddr,remoteaddr)创建一个新的调试服务器.参数是根据SMTPServer.消息将被丢弃,并打印在stdout上.