繁体   English   中英

Errno 10060 Python通过gmail发送电子邮件

[英]Errno 10060 python sending email through gmail

我正在尝试使用python 2.7通过gmail帐户发送电子邮件。 我的代码如下,任何帮助,感激不尽! 我不断得到:

Errno 10060-连接尝试失败,因为一段时间后连接方未正确响应...

import smtplib

FROMADDR = "myemail@gmail.com"
LOGIN    = FROMADDR
PASSWORD = "mypassword"
TOADDRS  = "toEmail@gmail.com"
msg = "Test message"
server = smtplib.SMTP('smtp.gmail.com', 25, timeout=120)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login(LOGIN, PASSWORD)
server.sendmail(FROMADDR, TOADDRS, msg)
server.quit()
print "E-mail succesfully sent"

之所以超时,是因为您正在连接端口以进行服务器之间的电子邮件路由,而不是邮件提交代理端口。 当使用端口587时,对我来说效果很好:

>>> import smtplib
>>> server = smtplib.SMTP('smtp.gmail.com',587)
>>> server.ehlo()
(250, 'mx.google.com at your service, [99.178.174.213]\nSIZE 35882577\n8BITMIME\nSTARTTLS\nENHANCEDSTATUSCODES')
>>> server.starttls()
(220, '2.0.0 Ready to start TLS')
>>> server.ehlo
<bound method SMTP.ehlo of <smtplib.SMTP instance at 0x1e518c0>>
>>> server.login('xxxxxxxxxxxx','xxxxxxxx')
(235, '2.7.0 Accepted')
>>> msg = "test message"
>>> server.sendmail('xxxxxxxxxxxx@gmail.com','xxxxxxx@yahoo.com',msg)
{}
>>> server.quit()
(221, '2.0.0 closing connection xxxxxxxxxxxxx.x - gsmtp')

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM