【发布时间】:2015-06-13 10:17:53
【问题描述】:
我正在尝试在 Django 1.7 中使用标准的 send_email(来自 django.core.mail 导入 send_mail)。
我有以下电话:
send_mail('subject', 'body', 'sender@example.com', ['me@example.com'], fail_silently=False)
还有我的 settings.py:
EMAIL_USE_TLS=True
EMAIL_BACKEND='django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST='mail.example.com'
EMAIL_PORT=587
EMAIL_HOST_USER='sender'
EMAIL_HOST_PASSWORD='password'
DEFAULT_FROM_EMAIL='sender@example.com'
这给了我在 Django 中的错误:
SMTPAuthenticationError: (535, '5.7.8 Error: authentication failed: authentication failure')
在我的后缀邮件中:
Apr 8 12:33:10 ip-172-30-0-149 postfix/smtpd[26859]: warning: unknown[<mxip>]: SASL PLAIN authentication failed: authentication failure
但是,如果我执行以下操作:
## Email the code
from django.core.mail import send_mail
from django.core.mail.backends.smtp import EmailBackend
from django.core.mail import EmailMessage
eb = EmailBackend(host='mail.example.com', port=587, username='sender', password='password', use_tls=True, fail_silently=False)
eb.open()
email = EmailMessage('Test', 'message ', 'sender@example.com', ['me@example.com'], [])
eb.send_messages( [email] )
eb.close()
一切正常。
据我所知,上面的设置与我的 settings.py 文件中的 EMAIL 设置相同。
知道为什么我尝试使用 send_mail(我的首选)与 EmailBackend 相比会收到错误吗??
【问题讨论】: