0

I'm trying to send email through Django with the default SMTP backend. I configured my settings:

EMAIL_HOST = 'mail.mydomain.nl'
EMAIL_HOST_USER = 'myusername'
EMAIL_PASSWORD = 'mypassword'
EMAIL_PORT = 587
EMAIL_USE_TLS = True

This is my company's own email server. When I try manage.py sendtestemail or send_mail in a view I keep getting the following error:

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

I made this small script to test sending from pure Python and it works fine:

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

Is there something in Django's SMTP EmailBackend that I am not aware of that could be causing the problem? This is Django 1.11.1 on Python 3.6 .

voodoo-burger
  • 2,123
  • 3
  • 22
  • 29
  • Is your `DEFAULT_FROM_EMAIL` the same as `sender` in your test script? – Alasdair May 09 '17 at 12:57
  • @Alasdair yes, although I have to login with `me.mydomain.nl` instead of `me@mydomain.nl`, so `DEFAULT_FROM_EMAIL = 'me@mydomain.nl'` while the login user is `me.mydomain.nl`. But I have tried settings both to the same format and that didn't make a difference. – voodoo-burger May 09 '17 at 13:07
  • Edit your Q to add django code that sends the email so it will be easy to debug! – Abijith Mg May 09 '17 at 13:17
  • Also check this: http://stackoverflow.com/questions/5623830/smtprecipientsrefused-in-django – Abijith Mg May 09 '17 at 13:26

0 Answers0