【问题标题】:SMTP AUTH extension not supported by server in python 2.4python 2.4 中的服务器不支持 SMTP AUTH 扩展
【发布时间】:2012-03-02 05:37:36
【问题描述】:

这是我在提供 python 2.4 的 VPS 主机中的正常代码

def mail(receiver,Message):
    import smtplib
    try:
        s=smtplib.SMTP()
        s.connect("smtp.gmail.com",465)
        s.login("email@gmail.com", "password")
        s.sendmail("email@gmail.com", receiver, Message)
    except Exception,R:
            return R

但很遗憾返回此消息! : SMTP AUTH extension not supported by server.

在我安装了 python 2.7 的计算机上,我找到了解决方案,它的工作非常好,这里是这段代码:

def mail(T,M):
    import smtplib
    try:
        s=smtplib.SMTP_SSL()
        s.connect("smtp.gmail.com",465)
        s.login("xxxxx@gmail.com","your_password")
        s.sendmail("xxxxx@gmail.com", T, M)
    except Exception,R:
            print R

但是在安装了python 2.4的VPS中没有SMTP_SSL()并返回此消息'module' object has no attribute 'SMTP_SSL'

我也尝试在 VPS 中升级我的 python,但发生的事情是损坏了整个 python,这意味着 python 根本无法工作。

【问题讨论】:

    标签: python linux smtp vps python-2.4


    【解决方案1】:

    谢谢大家,我找到了解决方案,这就是解决方案 =)

    def mail(receiver,Message):
        import smtplib
        try:
            s=smtplib.SMTP()
            s.connect("smtp.gmail.com",465)
            s.ehlo()
            s.starttls()
            s.ehlo()
            s.login("email@gmail.com", "password")
            s.sendmail("email@gmail.com", receiver, Message)
        except Exception,R:
                return R
    

    【讨论】:

    • 您不能在connection 之前运行ehlostarttls。除了没有任何意义之外,它还会引发异常 (SMTPServerDisconnected)。
    • 您不需要进行第一次 s.ehlo() 调用。 s.starttls() 会为你调用它。我在 2.7 中确认了这一点,2.4 文档听起来与该版本中的行为方式相同。
    • 可能值得明确地说,似乎是双 ehlo() 使这项工作..
    【解决方案2】:

    SMTP.starttls() 可用吗?你也可以这样做:

    def mail(receiver,Message):
        import smtplib
        try:
            s=smtplib.SMTP()
            s.connect("smtp.gmail.com",587)
            s.starttls()
            s.login("email@gmail.com", "password")
            s.sendmail("email@gmail.com", receiver, Message)
        except Exception,R:
                return R
    

    【讨论】:

    • 确切结果^_^ SMTP AUTH extension not supported by server
    猜你喜欢
    • 2022-06-17
    • 2016-09-10
    • 1970-01-01
    • 1970-01-01
    • 2012-08-10
    • 2013-11-14
    • 1970-01-01
    • 2011-09-15
    相关资源
    最近更新 更多