我真的需要你的帮助!当我尝试发送电子邮件时,我收到一个奇怪的错误。
后端(django 1.6.5):
EMAIL_BACKEND = 'django_smtp_ssl.SSLEmailBackend'
EMAIL_HOST = "mail.example.com"
EMAIL_PORT = 465
EMAIL_HOST_USER = "example_mail@mail.com"
EMAIL_HOST_PASSWORD = "example_pass"
回溯:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django/core/mail/__init__.py", line 50, in send_mail
connection=connection).send()
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django/core/mail/message.py", line 274, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 87, in send_messages
new_conn_created = self.open()
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django_smtp_ssl.py", line 14, in open
self.connection.login(self.username, self.password)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 615, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, '5.7.8 Error: authentication failed: authentication failure')
也许其他人已经解决了这个问题?
send_mail('test email', 'hello', '', ['example@gmail.com'])
connect: ('mail.example.com', 465)
connect: ('mail.example.com', 465)
reply: '220 relay.example.com ESMTP Postfix\r\n'
reply: retcode (220); Msg: relay.example.com ESMTP Postfix
connect: relay.example.com ESMTP Postfix
send: 'ehlo maxs-mbp-2.dlink\r\n'
reply: '250-relay.example.com\r\n'
reply: '250-PIPELINING\r\n'
reply: '250-SIZE 104857600\r\n'
reply: '250-ETRN\r\n'
reply: '250-AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5\r\n'
reply: '250-AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5\r\n'
reply: '250-ENHANCEDSTATUSCODES\r\n'
reply: '250-8BITMIME\r\n'
reply: '250 DSN\r\n'
reply: retcode (250); Msg: relay.example.com
PIPELINING
SIZE 104857600
ETRN
AUTH LOGIN PLAIN DIGEST-MD5 CRAM-MD5
AUTH=LOGIN PLAIN DIGEST-MD5 CRAM-MD5
ENHANCEDSTATUSCODES
8BITMIME
DSN
send: 'AUTH CRAM-MD5\r\n'
reply: '334 PDM3NDg0NzcwODMuNDc5ODUzNEByZWxheS5yc2h1LnJ1Pg==\r\n'
reply: retcode (334); Msg: PDM3NDg0NzcwODMuNDc5ODUzNEByZWxheS5yc2h1LnJ1Pg==
send: '...\r\n'
reply: '535 5.7.8 Error: authentication failed: authentication failure\r\n'
reply: retcode (535); Msg: 5.7.8 Error: authentication failed: authentication failure
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django/core/mail/__init__.py", line 50, in send_mail
connection=connection).send()
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django/core/mail/message.py", line 274, in send
return self.get_connection(fail_silently).send_messages([self])
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 87, in send_messages
new_conn_created = self.open()
File "/Users/User/.virtualenvs/rshu/lib/python2.7/site-packages/django_smtp_ssl.py", line 14, in open
self.connection.login(self.username, self.password)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 615, in login
raise SMTPAuthenticationError(code, resp)
SMTPAuthenticationError: (535, '5.7.8 Error: authentication failed: authentication failure')
>>>
新后端:
class SSLEmailBackend(EmailBackend):
def open(self):
if self.connection:
return False
try:
self.connection = smtplib.SMTP_SSL(
self.host, self.port, local_hostname=DNS_NAME.get_fqdn())
if self.username and self.password:
self.connection.ehlo()
# Remove CRAM-MD5 authentication method
self.connection.esmtp_features['auth'] = 'PLAIN LOGIN'
self.connection.login(self.username, self.password)
return True
except:
if not self.fail_silently:
raise