Django - SMTPSender从联系表单发送电子邮件时拒绝

时间:2015-11-27 22:18:20

标签: python django email smtp gmail

我创建了一个页面,当在表单内单击提交按钮时,该页面应该向to_email发送电子邮件。我使用this link禁用了验证码,因为我在this video playlist中被告知我一直在关注教程,但出于某种原因,我收到了身份验证错误。我找到了类似问题here的答案,但它涉及使用HOST_password文件中settings.py的字符串版本,我已经在做了。我使用的电子邮件和密码是正确的,那么可能导致问题的原因是什么?

以下是页面中的追溯日志:

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/ceyron/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')

1 个答案:

答案 0 :(得分:1)

您拼错了其中一个设置。你有:

EMAIL_HOSTS_USER = '<your email>'

应该是:

EMAIL_HOST_USER = '<your email>'