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 = '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()

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

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: Jon@MacBookPro.com
To: jon.crowell@yahoo.com
X-Peer: 127.0.0.1
line one
line two
line three
------------ END MESSAGE ------------

但是当我查看我的雅虎邮箱地址时,邮件始终没有收到。我已经等了大约5分钟,我认为这已经足够了。我做错了什么?

来自smtpd文档

类smtpd。DebuggingServer (localaddr remoteaddr)创建一个新的调试服务器。参数与SMTPServer一致。消息将被丢弃,并在stdout上打印。

调试邮件消息和查看幕后的好方法,只需设置smtp对象的debuglevel:

debuglevel = True
mail = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
mail.set_debuglevel(debuglevel)
mail.starttls()
mail.login(SMTP_USERNAME, SMTP_PASSWORD)
mail.sendmail(EMAIL_FROM, EMAIL_TO, msg.as_string())
mail.quit()

这允许您查看过程中的步骤/检查:

send: 'ehlo localhost.localdomainrn'
reply: '250-smtp.mail.yahoo.comrn'
reply: '250-PIPELININGrn'
reply: '250-SIZE 41697280rn'
reply: '250-8 BITMIMErn'
reply: '250-AUTH PLAIN LOGIN XYMCOOKIErn'
reply: '250 STARTTLSrn'
reply: retcode (250); Msg: smtp.mail.yahoo.com
PIPELINING
SIZE 41697280
8 BITMIME
AUTH PLAIN LOGIN XYMCOOKIE
STARTTLS
send: 'STARTTLSrn'
reply: '220 2.0.0 Start TLSrn'
reply: retcode (220); Msg: 2.0.0 Start TLS
send: 'ehlo localhost.localdomainrn'
reply: '250-smtp.mail.yahoo.comrn'
reply: '250-PIPELININGrn'
reply: '250-SIZE 41697280rn'
reply: '250-8 BITMIMErn'
reply: '250 AUTH PLAIN LOGIN XYMCOOKIErn'
reply: retcode (250); Msg: smtp.mail.yahoo.com
PIPELINING
SIZE 41697280
8 BITMIME
AUTH PLAIN LOGIN XYMCOOKIE
send: 'AUTH PLAIN AGZlZHVzcaddfjbkejkjkVAeWFob28uY29tAG1taHR0ODAxQA==rn'
reply: '235 2.0.0 OKrn'
reply: retcode (235); Msg: 2.0.0 OK
send: 'mail FROM:<example@yahoo.com> size=471rn'
reply: '250 OK , completedrn'
reply: retcode (250); Msg: OK , completed
send: 'rcpt TO:<example@gmail.com>rn'
reply: '250 OK , completedrn'
reply: retcode (250); Msg: OK , completed
send: 'datarn'
reply: '354 Start Mail. End with CRLF.CRLFrn'
reply: retcode (354); Msg: Start Mail. End with CRLF.CRLF
data: (354, 'Start Mail. End with CRLF.CRLF')
send: 'Content-Type: text/plain; charset="us-ascii"rnMIME-Version: 1.0rnContent-Transfer-Encoding: 7bitrnSubject: REMINDER:Company - Service at appointmentTimernFrom: example@yahoo.comrnTo: example@gmail.comrnrnrnHello, [username]! Just wanted to send a friendly appointmentrnreminder for your appointment:rn[Company]rnWhere: [companyAddress]rnTime: [appointmentTime]rnrnCompany URL: [companyUrl]rnrnChange appointment?? Add Service??rnrnchange notification preference (text msg/email)rn.rn'
reply: '250 OK , completedrn'
reply: retcode (250); Msg: OK , completed
data: (250, 'OK , completed')
send: 'quitrn'
reply: '221 Service Closing transmissionrn'
reply: retcode (221); Msg: Service Closing transmission

相关内容

  • 没有找到相关文章

最新更新