smtplib.SMTPResponseException: 535 不正确的身份验证数据 Apache,python,smtplib 模块
smtplib.SMTPResponseException: 535 Incorrect authentication data Apache, python, smtplib module
我正在尝试通过我大学的 SMTP 服务器发送电子邮件。我写了一些 python 代码。代码本身工作正常,但我认为 SMTP 服务器有问题。我想我应该联系管理员,但我应该告诉他什么?真的是服务器问题吗?我的代码如下所示:
import smtplib
import string
fromaddr = str('from@subunidomain.server.com')
password = str('secretpass')
toaddrs = 'to@unidomain.com'
server_smtp = 'smtp.server.com'
port_smtp = 465
msg = 'There was a terrible error that occured and I wanted you to know'
BODY = string.join((
"From: %s" % fromaddr,
"To: %s" % toaddrs,
"Subject: %s" % 'Hello' ,
"",
'Hello'
), "\r\n")
try :
server = smtplib.SMTP_SSL(host=server_smtp, port=port_smtp)
server.set_debuglevel(True)
server.login(fromaddr,password)
server.sendmail(fromaddr, toaddrs, str(BODY))
server.quit()
except smtplib.SMTPServerDisconnected :
print "smtplib.SMTPServerDisconnected"
except smtplib.SMTPResponseException, e:
print "smtplib.SMTPResponseException: " + str(e.smtp_code) + " " + str(e.smtp_error)
except smtplib.SMTPSenderRefused:
print "smtplib.SMTPSenderRefused"
except smtplib.SMTPRecipientsRefused:
print "smtplib.SMTPRecipientsRefused"
except smtplib.SMTPDataError:
print "smtplib.SMTPDataError"
except smtplib.SMTPConnectError:
print "smtplib.SMTPConnectError"
except smtplib.SMTPHeloError:
print "smtplib.SMTPHeloError"
except smtplib.SMTPAuthenticationError:
print "smtplib.SMTPAuthenticationError"
except Exception :
print "Exception"
我从服务器收到这样的响应:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-smtp.server.com Hello [127.0.1.1] [219.104.12.12]\r\n'
reply: '250-SIZE 78643200\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-AUTH PLAIN LOGIN\r\n'
reply: '250 HELP\r\n'
reply: retcode (250); Msg: smtp.server.com Hello [127.0.1.1] [219.104.12.12]
SIZE 78643200
PIPELINING
AUTH PLAIN LOGIN
HELP
send: 'AUTH PLAIN AGFpQGluZm9ybWF0aWNhLnVtY3MubHVibGluLnBsAGFubmFsZXN1bWNzMjAxNQ==\r\n'
reply: '535 Incorrect authentication data\r\n'
reply: retcode (535); Msg: Incorrect authentication data
smtplib.SMTPResponseException: 535 Incorrect authentication data
问题是什么以及如何解决? 我的密码和电子邮件 100% 正确。
这是 https://pingability.com/smtptest.jsp 的输出(用户名: from - 当我尝试写 from @subunidomain.server.com 相反,它不起作用):
smtp.server.com
SMTP Username from
Output
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.server.com", port 25, isSSL false
220-smtp.server.com ESMTP Exim 4.69 #1 Wed, 29 Apr 2015 23:05:53 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
DEBUG SMTP: connected to host "smtp.server.com", port: 25
EHLO localhost
250-smtp.server.com Hello pingability.com [72.249.37.67]
250-SIZE 78643200
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "78643200"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
YWk=
334 UGFzc3dvcmQ6
YW5uYWxlc3VtY3MyMDE1
235 Authentication succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<smtptester@pingability.com>
250 OK
RCPT TO:<smtptester@pingability.com>
250 Accepted
DEBUG SMTP: Verified Addresses
DEBUG SMTP: smtptester@pingability.com
DATA
354 Enter message, ending with "." on a line by itself
Date: Wed, 29 Apr 2015 21:05:53 +0000 (UTC)
From: smtptester@pingability.com
To: smtptester@pingability.com
Message-ID: <8486466.51545.1430341553138.JavaMail.tomcat@localhost>
Subject: Pingability Test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Pingability Test
.
250 OK id=1YnZB5-0006N0-Nd
QUIT
221 smtp.server.com closing connection
也许您可以尝试使用 yagmail
发送消息。
安装:
pip install yagmail
然后导入,创建连接对象并发送邮件:
import yagmail
yag = yagmail.Connect('user', 'pass', server_smtp, port_smtp, set_debuglevel = 1)
yag.send(toaddrs, Subject = 'Hello', Body = 'Hello')
如果您遇到任何错误,请告诉我。
Disclaimer/Background:我是 yagmail
的 maintainer/developer。
这个包的目的是让很多事情在发送电子邮件时变得非常方便。例如,您可以利用它的特性,不在脚本中写入您的密码,而是将其存储在您的密钥环中(非常安全,您可以在 github 上阅读相关内容!)。
它还有一些方法可以让它更短,例如:
from yagmail import Connect
yag = Connect(host = server_smtp, port = port_smtp, set_debuglevel = 1)
yag.send(toaddrs, 'Hello', 'Hello')
附件(如HTML/images)确实好用,但没人问我就不去了。最后,只要它超出范围,它就会自动退出。
我正在尝试通过我大学的 SMTP 服务器发送电子邮件。我写了一些 python 代码。代码本身工作正常,但我认为 SMTP 服务器有问题。我想我应该联系管理员,但我应该告诉他什么?真的是服务器问题吗?我的代码如下所示:
import smtplib
import string
fromaddr = str('from@subunidomain.server.com')
password = str('secretpass')
toaddrs = 'to@unidomain.com'
server_smtp = 'smtp.server.com'
port_smtp = 465
msg = 'There was a terrible error that occured and I wanted you to know'
BODY = string.join((
"From: %s" % fromaddr,
"To: %s" % toaddrs,
"Subject: %s" % 'Hello' ,
"",
'Hello'
), "\r\n")
try :
server = smtplib.SMTP_SSL(host=server_smtp, port=port_smtp)
server.set_debuglevel(True)
server.login(fromaddr,password)
server.sendmail(fromaddr, toaddrs, str(BODY))
server.quit()
except smtplib.SMTPServerDisconnected :
print "smtplib.SMTPServerDisconnected"
except smtplib.SMTPResponseException, e:
print "smtplib.SMTPResponseException: " + str(e.smtp_code) + " " + str(e.smtp_error)
except smtplib.SMTPSenderRefused:
print "smtplib.SMTPSenderRefused"
except smtplib.SMTPRecipientsRefused:
print "smtplib.SMTPRecipientsRefused"
except smtplib.SMTPDataError:
print "smtplib.SMTPDataError"
except smtplib.SMTPConnectError:
print "smtplib.SMTPConnectError"
except smtplib.SMTPHeloError:
print "smtplib.SMTPHeloError"
except smtplib.SMTPAuthenticationError:
print "smtplib.SMTPAuthenticationError"
except Exception :
print "Exception"
我从服务器收到这样的响应:
send: 'ehlo [127.0.1.1]\r\n'
reply: '250-smtp.server.com Hello [127.0.1.1] [219.104.12.12]\r\n'
reply: '250-SIZE 78643200\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-AUTH PLAIN LOGIN\r\n'
reply: '250 HELP\r\n'
reply: retcode (250); Msg: smtp.server.com Hello [127.0.1.1] [219.104.12.12]
SIZE 78643200
PIPELINING
AUTH PLAIN LOGIN
HELP
send: 'AUTH PLAIN AGFpQGluZm9ybWF0aWNhLnVtY3MubHVibGluLnBsAGFubmFsZXN1bWNzMjAxNQ==\r\n'
reply: '535 Incorrect authentication data\r\n'
reply: retcode (535); Msg: Incorrect authentication data
smtplib.SMTPResponseException: 535 Incorrect authentication data
问题是什么以及如何解决? 我的密码和电子邮件 100% 正确。
这是 https://pingability.com/smtptest.jsp 的输出(用户名: from - 当我尝试写 from @subunidomain.server.com 相反,它不起作用):
smtp.server.com
SMTP Username from
Output
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.server.com", port 25, isSSL false
220-smtp.server.com ESMTP Exim 4.69 #1 Wed, 29 Apr 2015 23:05:53 +0200
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
DEBUG SMTP: connected to host "smtp.server.com", port: 25
EHLO localhost
250-smtp.server.com Hello pingability.com [72.249.37.67]
250-SIZE 78643200
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
DEBUG SMTP: Found extension "SIZE", arg "78643200"
DEBUG SMTP: Found extension "PIPELINING", arg ""
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Found extension "HELP", arg ""
DEBUG SMTP: Attempt to authenticate
DEBUG SMTP: check mechanisms: LOGIN PLAIN DIGEST-MD5 NTLM
AUTH LOGIN
334 VXNlcm5hbWU6
YWk=
334 UGFzc3dvcmQ6
YW5uYWxlc3VtY3MyMDE1
235 Authentication succeeded
DEBUG SMTP: use8bit false
MAIL FROM:<smtptester@pingability.com>
250 OK
RCPT TO:<smtptester@pingability.com>
250 Accepted
DEBUG SMTP: Verified Addresses
DEBUG SMTP: smtptester@pingability.com
DATA
354 Enter message, ending with "." on a line by itself
Date: Wed, 29 Apr 2015 21:05:53 +0000 (UTC)
From: smtptester@pingability.com
To: smtptester@pingability.com
Message-ID: <8486466.51545.1430341553138.JavaMail.tomcat@localhost>
Subject: Pingability Test
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
Pingability Test
.
250 OK id=1YnZB5-0006N0-Nd
QUIT
221 smtp.server.com closing connection
也许您可以尝试使用 yagmail
发送消息。
安装:
pip install yagmail
然后导入,创建连接对象并发送邮件:
import yagmail
yag = yagmail.Connect('user', 'pass', server_smtp, port_smtp, set_debuglevel = 1)
yag.send(toaddrs, Subject = 'Hello', Body = 'Hello')
如果您遇到任何错误,请告诉我。
Disclaimer/Background:我是 yagmail
的 maintainer/developer。
这个包的目的是让很多事情在发送电子邮件时变得非常方便。例如,您可以利用它的特性,不在脚本中写入您的密码,而是将其存储在您的密钥环中(非常安全,您可以在 github 上阅读相关内容!)。
它还有一些方法可以让它更短,例如:
from yagmail import Connect
yag = Connect(host = server_smtp, port = port_smtp, set_debuglevel = 1)
yag.send(toaddrs, 'Hello', 'Hello')
附件(如HTML/images)确实好用,但没人问我就不去了。最后,只要它超出范围,它就会自动退出。