Linux python 2.4中的服务器不支持SMTP AUTH扩展

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9216127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 04:29:30  来源:igfitidea点击:

SMTP AUTH extension not supported by server in python 2.4

pythonlinuxsmtpvpspython-2.4

提问by Hamoudaq

This is my normal code in my VPS hosting which provide python 2.4

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

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

but unfortunately return this message! : SMTP AUTH extension not supported by server.

但不幸的是返回此消息!: SMTP AUTH extension not supported by server.

in my computer which i've install python 2.7 i found the solution and it's work very good here is this code :

在我安装了 python 2.7 的计算机中,我找到了解决方案,这里的代码非常好用:

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

But in the VPS which installed python 2.4 doesn't have SMTP_SSL() and return this message 'module' object has no attribute 'SMTP_SSL'

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

Also i've tried to upgrade my python in VPS but what happened is Damage the whole python that mean python not work at all.

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

采纳答案by Hamoudaq

Guys thanks i've found the solution and this is the solution =)

伙计们,谢谢我找到了解决方案,这就是解决方案 =)

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 protected]", "password")
        s.sendmail("[email protected]", receiver, Message)
    except Exception,R:
            return R

回答by ldx

Is SMTP.starttls()available? You can also do e.g.:

是否SMTP.starttls()可用?你也可以做例如:

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