我正在尝试使用默认的SMTP后端通过Django发送电子邮件。我配置了我的设置:
EMAIL_HOST = 'mail.mydomain.nl'
EMAIL_HOST_USER = 'myusername'
EMAIL_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True
这是我公司自己的电子邮件服务器。当我在视图中尝试manage.py sendtestemail
或send_mail
时,我不断收到以下错误:
smtplib.SMTPRecipientsRefused: {'personalemail@gmail.com': (554, b'5.7.1 <52D95A25.cm-11-1b.dynamic.ziggo.nl[X.X.X.X]>: Client host rejected: Access denied')}
我制作了这个小脚本来测试纯Python的发送,它运行正常:
import smtplib
sender = 'me@mydomain.nl'
receivers = ['personalemail@gmail.com']
message = 'This script works.'
try:
smtpObj = smtplib.SMTP('mail.mydomain.nl', 587)
smtpObj.login('username', 'password')
smtpObj.sendmail(sender, receivers, message)
print('Successfully sent email')
except Exception as e:
print('Error unable to send email {0}'.format(e))
Django的SMTP EmailBackend中有什么东西我不知道这可能导致问题吗?这是Python 3.6上的Django 1.11.1。