【问题标题】:STARTTLS extension not supported by server服务器不支持 STARTTLS 扩展
【发布时间】:2011-09-15 09:00:33
【问题描述】:

这可能是一个重复的问题,但我仍然面临这方面的问题,希望有一个解决方案。提前致谢。

我正在尝试通过公司的服务器发送邮件

我目前使用的是 Python 2.6 和 Ubuntu 10.04

这是我收到的错误消息

Traceback (most recent call last):

  File "hxmass-mail-edit.py", line 227, in <module>
    server.starttls()

  File "/usr/lib/python2.6/smtplib.py", line 611, in starttls
    raise SMTPException("STARTTLS extension not supported by server.") smtplib.SMTPException: STARTTLS extension not supported by server.

这里是部分代码

server = smtplib.SMTP('smtp.abc.com', 587)
server.set_debuglevel(1)
server.ehlo()
server.starttls()
server.ehlo()
server.login('sales@abc.com', 'abc123')
addressbook=sys.argv[1]

【问题讨论】:

  • 请张贴您的邮件发送代码的sn-p。也许删除“server.starttls()”就足够了,但是没有代码很难分辨

标签: python email


【解决方案1】:

错误说明了一切,看来您正在使用的 SMTP 服务器不支持 STARTTLS 并且您发出 server.starttls()。尝试使用服务器而不调用server.starttls()

我只能说没有更多信息。

【讨论】:

  • 感谢 ferran,我试过不使用 server.starttls(),返回错误列表似乎效果不佳。
  • 它帮助了我。谢谢
  • 这也可能行不通。如果您完全跳过,您可能会看到类似 smtplib.SMTPException: No suitable authentication method found. 的内容,因此您仍然需要找出服务器用于身份验证的内容。
【解决方案2】:

您确定要加密 (StartTLS) 与邮件服务器的连接吗?我会联系了解该服务器内部的人,看看使用什么协议/加密。

您说在删除对server.starttls() 的调用后,您会收到一系列不同的错误消息。能否请您也发布这些消息?

此外,您可能需要阅读 StartTLS,以便了解它是什么以及为什么要使用它。看来您正在编写一个严肃的业务程序,在这种情况下,您可能想了解自己在做什么,安全方面。

【讨论】:

    【解决方案3】:

    删除starttls()之前的ehlo()

    starttls() + ehlo() 产生两条 HELLO 消息,导致服务器删除回复消息中的 STARTTLS

    server = smtplib.SMTP('smtp.abc.com', 587)
    server.starttls()
    server.ehlo()
    server.login('sales@abc.com', 'abc123')
    

    【讨论】:

    • 这不适用于雅虎。雅虎仅在我删除 startTLS 时工作。但我需要 TLS 以确保密码不被嗅探器捕获。
    【解决方案4】:

    server.starttls() 之前删除server.ehlo() 帮助我让我的代码正常工作!谢谢你,伦纳德! 我的代码:

    s = smtplib.SMTP("smtp.gmail.com",587)
    s.starttls()
    s.ehlo
    try:
        s.login(gmail_user, gmail_psw)
    except SMTPAuthenticationError:
        print 'SMTPAuthenticationError'
    s.sendmail(gmail_user, to, msg.as_string())
    s.quit()
    

    【讨论】:

      【解决方案5】:

      是的,将server.starttls() 放在server.ehlo() 上方解决了这个问题。

      【讨论】:

        【解决方案6】:

        我可以通过添加带有服务器名称的端口号来使用以下代码解决问题:

        server = smtplib.SMTP('smtp.abc.com:587')
        

        【讨论】:

        • 587为提交端口
        【解决方案7】:

        我在尝试通过公司的服务器发送邮件时遇到了类似的问题(无需身份验证)

        我解决了删除server.ehlo 并删除端口号的问题:

        server = smtplib.SMTP("smtp.mycompany.com")
        server.sendmail(fromaddr, toaddr, text)
        

        【讨论】:

          【解决方案8】:
          from smtplib import SMTP_SSL, SMTP, SMTPAuthenticationError
          from ssl import create_default_context
          from email.message import EmailMessage
          
          sender = 'aaa@bbb.com'
          description = "This is the test description supposed to be in body of the email."
          msg = EmailMessage()
          msg.set_content(description)
          msg['Subject'] = 'This is a test title'
          msg['From'] = f"Python SMTP <{sender}>"
          msg['To'] = 'bbb@ccc.com'
          
          
          def using_ssl():
              try:
                  server = SMTP_SSL(host='smtp.gmail.com', port=465, context=create_default_context())
                  server.login(sender, password)
                  server.send_message(msg=msg)
                  server.quit()
                  server.close()
              except SMTPAuthenticationError:
                  print('Login Failed')
          
          
          def using_tls():
              try:
                  server = SMTP(host='smtp.gmail.com', port=587)
                  server.starttls(context=create_default_context())
                  server.ehlo()
                  server.login(sender, password)
                  server.send_message(msg=msg)
                  server.quit()
                  server.close()
              except SMTPAuthenticationError:
                  print('Login Failed')
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2015-07-25
            • 2016-09-10
            • 1970-01-01
            • 1970-01-01
            • 2022-12-20
            相关资源
            最近更新 更多