2

On the vps where I host a django website, I have set up a postfix mailserver to be used by django for email. The mailserver works. Using mutt on the vps command line, I can send and receive mail to/from other accounts like gmail etc.

Still, I am having trouble using postfix to send mail from django.

I followed the advice in https://stackoverflow.com/a/28143166/1009979, with settings...

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

When I try

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

I get

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')}

When I google for advice about SMTPRecipientsRefused: or Helo command rejected: Host not found, no obvious solutions to my problems arise.

Is there something wrong with the settings?

I should mention that I have no general problem problem with django email. For example, I can send gmail emails from django (following settings and procedure described here https://stackoverflow.com/a/23402208/1009979).

Community
  • 1
  • 1
mjandrews
  • 2,392
  • 4
  • 22
  • 39

1 Answers1

1

Make sure you have permit_mynetworks in smtpd_helo_restrictions and smtpd_recipient_restrictions in /etc/postfix/main.cf

mjandrews
  • 2,392
  • 4
  • 22
  • 39