Python 的 SMTP AUTH 扩展问题
我正在尝试编写一个简单的 Python 脚本来通过我公司的 SMTP 服务器发送电子邮件。我正在使用下面的代码。
#! /usr/local/bin/python
import sys,re,os,datetime
from smtplib import SMTP
#Email function
def sendEmail(message):
sender="[email protected]"
receivers=['[email protected]','[email protected]']
subject="Daily Report - " + datetime.datetime.now().strftime("%d %b %y")
header="""\
From: %s
To: %s
Subject: %s
%s""" % (sender, ", ".join(receivers), subject, message)
smtp = SMTP()
smtp.set_debuglevel(1)
smtp.connect('X.X.X.X')
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
try:
smtp.login('[email protected]', '********')
smtp.sendmail(sender,receivers,header)
smtp.quit()
except Exception, e:
print e
#MAIN
sendEmail("HAHHAHAHAHAH!!!")
运行这个程序,会产生这个结果。
connect: ('X.X.X.X', 25)
connect: ('X.X.X.X', 25)
reply: '220 COMPANY.com [ESMTP Server] service ready;ESMTP Server; 05/25/11 15:59:27\r\n'
reply: retcode (220); Msg: COMPANY.com [ESMTP Server] service ready;ESMTP Server; 05/25/11 15:59:27
connect: COMPANY.com [ESMTP Server] service ready;ESMTP Server; 05/25/11 15:59:27
send: 'ehlo SERVER1.COMPANY.com\r\n'
reply: '250-COMPANY.com\r\n'
reply: '250-SIZE 15728640\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 STARTTLS\r\n'
reply: retcode (250); Msg: COMPANY.com
SIZE 15728640
8BITMIME
STARTTLS
send: 'STARTTLS\r\n'
reply: '220 Ready to start TLS\r\n'
reply: retcode (220); Msg: Ready to start TLS
send: 'ehlo SERVER2.COMPANY.com\r\n'
reply: '250-COMPANY.com\r\n'
reply: '250-SIZE 15728640\r\n'
reply: '250 8BITMIME\r\n'
reply: retcode (250); Msg: COMPANY.com
SIZE 15728640
8BITMIME
send: 'quit\r\n'
reply: '221 [ESMTP Server] service closing transmission channel\r\n'
reply: retcode (221); Msg: [ESMTP Server] service closing transmission channel
ERROR: Could not send email! Check the reason below.
SMTP AUTH extension not supported by server.
如何开始调试此“服务器不支持 SMTP AUTH 扩展”。错误?
PS:我知道 SMTP 详细信息和凭据是正确的,因为我有一个包含确切详细信息的工作 Java 类。
I am trying to write a simple Python script to send emails through my company's SMTP server. I am using the following piece of code.
#! /usr/local/bin/python
import sys,re,os,datetime
from smtplib import SMTP
#Email function
def sendEmail(message):
sender="[email protected]"
receivers=['[email protected]','[email protected]']
subject="Daily Report - " + datetime.datetime.now().strftime("%d %b %y")
header="""\
From: %s
To: %s
Subject: %s
%s""" % (sender, ", ".join(receivers), subject, message)
smtp = SMTP()
smtp.set_debuglevel(1)
smtp.connect('X.X.X.X')
smtp.ehlo()
smtp.starttls()
smtp.ehlo()
try:
smtp.login('[email protected]', '********')
smtp.sendmail(sender,receivers,header)
smtp.quit()
except Exception, e:
print e
#MAIN
sendEmail("HAHHAHAHAHAH!!!")
Running this program, yields this result.
connect: ('X.X.X.X', 25)
connect: ('X.X.X.X', 25)
reply: '220 COMPANY.com [ESMTP Server] service ready;ESMTP Server; 05/25/11 15:59:27\r\n'
reply: retcode (220); Msg: COMPANY.com [ESMTP Server] service ready;ESMTP Server; 05/25/11 15:59:27
connect: COMPANY.com [ESMTP Server] service ready;ESMTP Server; 05/25/11 15:59:27
send: 'ehlo SERVER1.COMPANY.com\r\n'
reply: '250-COMPANY.com\r\n'
reply: '250-SIZE 15728640\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 STARTTLS\r\n'
reply: retcode (250); Msg: COMPANY.com
SIZE 15728640
8BITMIME
STARTTLS
send: 'STARTTLS\r\n'
reply: '220 Ready to start TLS\r\n'
reply: retcode (220); Msg: Ready to start TLS
send: 'ehlo SERVER2.COMPANY.com\r\n'
reply: '250-COMPANY.com\r\n'
reply: '250-SIZE 15728640\r\n'
reply: '250 8BITMIME\r\n'
reply: retcode (250); Msg: COMPANY.com
SIZE 15728640
8BITMIME
send: 'quit\r\n'
reply: '221 [ESMTP Server] service closing transmission channel\r\n'
reply: retcode (221); Msg: [ESMTP Server] service closing transmission channel
ERROR: Could not send email! Check the reason below.
SMTP AUTH extension not supported by server.
How do I start debugging this "SMTP AUTH extension not supported by server." error?
P.S.: I know the SMTP details and credentials are correct, as I have a working Java class with the exact details.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您收到的错误意味着您正在交谈的 SMTP 服务器不声称支持身份验证。如果查看调试输出,您会发现对
EHLO
的响应均不包含AUTH
的必要声明。如果它确实(正确)支持身份验证,则响应之一将类似于:(至少在
STARTTLS
之后响应EHLO
。)因为该响应不是“包括在内,smtplib 假定服务器无法处理 AUTH 命令,并将拒绝发送它。如果您确定您的 SMTP 服务器确实支持AUTH
命令,即使它没有公布它,您可以偷偷地说服 smtplib 它支持AUTH
code> 通过显式地将其添加到功能集中。您需要知道支持哪种身份验证方案,然后您可以执行以下操作:...但是当然,使 SMTP 服务器按照规范运行将是一个更好的主意:)
The error you get means the SMTP server you're talking to doesn't claim to support authentication. If you look at the debug output you'll see that none of the responses to your
EHLO
s contain the necessary declaration forAUTH
. If it did (properly) support authentication, one of the responses would be something like:(at least in reponse to the
EHLO
after theSTARTTLS
.) Because that response isn't included, smtplib assumes the server won't be able to handle theAUTH
command, and will refuse to send it. If you're certain your SMTP server does support theAUTH
command even though it doesn't advertise it, you can sneakily convince smtplib that it supportsAUTH
by explicitly adding it to the set of features. You'll need to know which kind of authentication schemes are supported, and then you can do:... but of course making the SMTP server behave according to spec would be a better idea :)