Django的;从我自己的postfix邮件服务器发送电子邮件

时间:2015-08-05 14:56:53

标签: python django email

在我主持django网站的vps上,我已经设置了一个postfix邮件服务器,供django用于电子邮件。邮件服务器工作。在vps命令行上使用mutt,我可以发送和接收来自其他帐户的邮件,如gmail等。

但是,我无法使用postfix从django发送邮件。

我按照https://stackoverflow.com/a/28143166/1009979中的建议进行了设置......

EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'localhost'
EMAIL_PORT = 25
EMAIL_HOST_USER = ''
EMAIL_HOST_PASSWORD = ''
EMAIL_USE_TLS = False

当我尝试

>>> from django.core.mail import send_mail
>>> send_mail('Subject here', 'Here is the message.', 'from@example.com', ['andrews.markw@gmail.com'])

我得到了

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/andrews/development/wilhelm-development/local/lib/python2.7/site-packages/django/core/mail/__init__.py", line 62, in send_mail
    return mail.send()
  File "/home/andrews/development/wilhelm-development/local/lib/python2.7/site-packages/django/core/mail/message.py", line 303, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/home/andrews/development/wilhelm-development/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 107, in send_messages
    sent = self._send(message)
  File "/home/andrews/development/wilhelm-development/local/lib/python2.7/site-packages/django/core/mail/backends/smtp.py", line 123, in _send
    self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
  File "/usr/lib/python2.7/smtplib.py", line 733, in sendmail
    raise SMTPRecipientsRefused(senderrs)
SMTPRecipientsRefused: {u'andrews.markw@gmail.com': (550, '5.7.1 <vps7718.webhosting.uk.com>: Helo command rejected: Host not found')}

当我谷歌获取有关SMTPRecipientsRefused:Helo command rejected: Host not found的建议时,我的问题没有明显的解决方案。

设置有问题吗?

我应该提一下,我对django电子邮件没有普遍的问题。例如,我可以从django发送gmail电子邮件(按照此处https://stackoverflow.com/a/23402208/1009979所述的设置和步骤)。

1 个答案:

答案 0 :(得分:1)

确保permit_mynetworks中的smtpd_helo_restrictionssmtpd_recipient_restrictions中的/etc/postfix/main.cf