Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python电子邮件-简单的示例运行时没有错误,但电子邮件永远不会到达_Python_Email_Smtp_Smtpd - Fatal编程技术网

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

python电子邮件-简单的示例运行时没有错误,但电子邮件永远不会到达,python,email,smtp,smtpd,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 fil

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

# 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-msmtpd-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.DebuggingServer(localaddr,remoteaddr) 创建一个新的调试服务器。参数与SMTPServer一致消息将被丢弃,并打印在标准输出上


调试邮件和查看幕后信息的好方法是,只需设置smtp对象的调试级别:

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.localdomain\r\n'
reply: '250-smtp.mail.yahoo.com\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 41697280\r\n'
reply: '250-8 BITMIME\r\n'
reply: '250-AUTH PLAIN LOGIN XYMCOOKIE\r\n'
reply: '250 STARTTLS\r\n'
reply: retcode (250); Msg: smtp.mail.yahoo.com
PIPELINING
SIZE 41697280
8 BITMIME
AUTH PLAIN LOGIN XYMCOOKIE
STARTTLS
send: 'STARTTLS\r\n'
reply: '220 2.0.0 Start TLS\r\n'
reply: retcode (220); Msg: 2.0.0 Start TLS
send: 'ehlo localhost.localdomain\r\n'
reply: '250-smtp.mail.yahoo.com\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 41697280\r\n'
reply: '250-8 BITMIME\r\n'
reply: '250 AUTH PLAIN LOGIN XYMCOOKIE\r\n'
reply: retcode (250); Msg: smtp.mail.yahoo.com
PIPELINING
SIZE 41697280
8 BITMIME
AUTH PLAIN LOGIN XYMCOOKIE
send: 'AUTH PLAIN AGZlZHVzcaddfjbkejkjkVAeWFob28uY29tAG1taHR0ODAxQA==\r\n'
reply: '235 2.0.0 OK\r\n'
reply: retcode (235); Msg: 2.0.0 OK
send: 'mail FROM:<example@yahoo.com> size=471\r\n'
reply: '250 OK , completed\r\n'
reply: retcode (250); Msg: OK , completed
send: 'rcpt TO:<example@gmail.com>\r\n'
reply: '250 OK , completed\r\n'
reply: retcode (250); Msg: OK , completed
send: 'data\r\n'
reply: '354 Start Mail. End with CRLF.CRLF\r\n'
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"\r\nMIME-Version: 1.0\r\nContent-Transfer-Encoding: 7bit\r\nSubject: REMINDER:Company - Service at appointmentTime\r\nFrom: example@yahoo.com\r\nTo: example@gmail.com\r\n\r\n\r\nHello, [username]! Just wanted to send a friendly appointment\r\nreminder for your appointment:\r\n[Company]\r\nWhere: [companyAddress]\r\nTime: [appointmentTime]\r\n\r\nCompany URL: [companyUrl]\r\n\r\nChange appointment?? Add Service??\r\n\r\nchange notification preference (text msg/email)\r\n.\r\n'
reply: '250 OK , completed\r\n'
reply: retcode (250); Msg: OK , completed
data: (250, 'OK , completed')
send: 'quit\r\n'
reply: '221 Service Closing transmission\r\n'
reply: retcode (221); Msg: Service Closing transmission
send:'ehlo localhost.localdomain\r\n'
答复:“250 smtp.mail.yahoo.com\r\n”
答复:“250-流水线\r\n”
答复:“250-SIZE 41697280\r\n”
答复:“250-8位MIME\r\n”
答复:“250-AUTH普通登录XYMCOOKIE\r\n”
答复:“250个STARTTLS\r\n”
答复:retcode(250);Msg:smtp.mail.yahoo.com
流水线
尺寸41697280
8位MIME
验证普通登录XYMCOOKIE
STARTTLS
发送:'STARTTLS\r\n'
答复:“220 2.0.0启动TLS\r\n”
答复:retcode(220);;消息:2.0.0启动TLS
发送:“ehlo localhost.localdomain\r\n”
答复:“250 smtp.mail.yahoo.com\r\n”
答复:“250-流水线\r\n”
答复:“250-SIZE 41697280\r\n”
答复:“250-8位MIME\r\n”
答复:“250身份验证普通登录XYMCOOKIE\r\n”
答复:retcode(250);Msg:smtp.mail.yahoo.com
流水线
尺寸41697280
8位MIME
验证普通登录XYMCOOKIE
send:'AUTH PLAIN agzlzhvzcadfjbkejkkjkvaewfob2uy29tag1tahr0odaxqa==\r\n'
答复:“235 2.0.0正常\r\n”
答复:retcode(235);;Msg:2.0.0正常
发送:“邮件发件人:大小=471\r\n”
答复:“250确定,已完成\r\n”
答复:retcode(250);Msg:好的,完成了
发送:'rcpt至:\r\n'
答复:“250确定,已完成\r\n”
答复:retcode(250);Msg:好的,完成了
发送:“数据\r\n”
回复:“354开始邮件。以CRLF结束。CRLF\r\n'
答复:retcode(354);;邮件开始。以CRLF结束
数据:(354,‘开始邮件。以CRLF结束。CRLF’)
发送:'内容类型:文本/普通;charset=“us ascii”\r\n时间版本:1.0\r\n内容传输编码:7bit\r\n对象:提醒:公司-预约时间服务\r\n来源:example@yahoo.com\r\n收件人:example@gmail.com\r\n\r\n\r\n Hello,[用户名]!只是想为您的约会发送一个友好的约会\r\n收件人:\r\n[公司]\r\n地址:[公司地址]\r\n时间:[约会时间]\r\n\r\n公司URL:[公司URL]\r\n\r\n更改约会??添加服务???\r\n\r\n更改通知首选项(文本消息/电子邮件)\r\n。\r\n'
答复:“250确定,已完成\r\n”
答复:retcode(250);Msg:好的,完成了
数据:(250,‘确定,完成’)
发送:“退出\r\n”
答复:“221服务正在关闭传输\r\n”
答复:retcode(221);;Msg:服务关闭传输