【问题标题】:Errno 10060 python sending email through gmailErrno 10060 python 通过 gmail 发送电子邮件
【发布时间】:2013-06-23 01:47:08
【问题描述】:

我正在尝试使用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"

【问题讨论】:

    标签: python email gmail


    【解决方案1】:

    超时是因为您连接的是端口for email routing between servers 而不是mail submission agent 端口。使用端口 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')
    

    【讨论】:

    • 那行得通——另一个问题是我无法通过网络防火墙连接到另一台服务器。它也会导致连接超时。我的代码运行良好,可以在家中发送电子邮件,但在工作时却不行。您能想到任何简单的解决方法吗?谢谢!
    猜你喜欢
    • 2023-01-30
    • 2016-09-09
    • 1970-01-01
    • 2012-01-07
    • 2023-03-19
    • 2019-02-04
    • 2015-09-28
    相关资源
    最近更新 更多