Search code examples
pythondjangoemailsmtpgmail

Django - SMTPSenderRefused when sending email from contact form


I've made a page that is supposed to send an email to the to_email when the submit button is clicked inside of a form. I disabled captchas using this link as I was advised in this video playlist that I've been following for tutorials but for some reason, I'm getting an authentication error. I found an answer to a similar problem here but it involved using the string version of the HOST_password in the settings.py file, which I am already doing. The emails and passwords that I am using are correct, so what could be causing the problem?

Below is the traceback log from the page:

Django Version: 1.8.6
Python Version: 2.7.6
Installed Applications:
('django.contrib.admin',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.sessions',
 'django.contrib.messages',
 'django.contrib.staticfiles',
 'artist_tracker')
Installed Middleware:
('django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.common.CommonMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware',
 'django.middleware.clickjacking.XFrameOptionsMiddleware',
 'django.middleware.security.SecurityMiddleware')


Traceback:
File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py" in get_response
  132.                     response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/www/students/test/bandsync/src/bandsync-repo/artist_tracker/views.py" in contact
  58.       send_mail(subject, contact_message, from_email, to_email, fail_silently =False)
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/__init__.py" in send_mail
  62.     return mail.send()
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/message.py" in send
  303.         return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py" in send_messages
  107.                 sent = self._send(message)
File "/usr/local/lib/python2.7/dist-packages/django/core/mail/backends/smtp.py" in _send
  123.             self.connection.sendmail(from_email, recipients, message.as_bytes(linesep='\r\n'))
File "/usr/lib/python2.7/smtplib.py" in sendmail
  731.             raise SMTPSenderRefused(code, resp, from_addr)

Exception Type: SMTPSenderRefused at /contact/
Exception Value: (530, '5.5.1 Authentication Required. Learn more at\n5.5.1  https://support.google.com/mail/answer/14257 l85sm10088128qhl.3 - gsmtp', u'webmaster@localhost')

Solution

  • You have misspelled one of your settings. You have:

    EMAIL_HOSTS_USER = '<your email>'
    

    It should be:

    EMAIL_HOST_USER = '<your email>'