我複製並粘貼這個例子,並填寫我自己的電子郵件地址。Python電子郵件 - 簡單的例子運行沒有錯誤,但電子郵件永遠不會到達
# 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 = '[email protected]'
you = '[email protected]'
# 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()
我再打開另一個終端窗口,運行以下命令:
python -m smtpd -n -c DebuggingServer localhost:1025
當我運行該文件以發送電子郵件,它完成沒有錯誤,並且正在運行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: [email protected]
To: [email protected]
X-Peer: 127.0.0.1
line one
line two
line three
------------ END MESSAGE ------------
但是,當我檢查我的雅虎電子郵件地址,電子郵件從未收到。我等了大約5分鐘,我認爲這是足夠的。我做錯了什麼?
哈哈,爲我複製粘貼而不理解...... – jononomo