3

我在测试帐户注册表单时收到此错误。我正在使用 django-registration 包。我有所有必要的模板文件。我正在使用 WebFaction 进行托管。我是 Django 和 Python 的初学者。请像我五岁一样跟我说话。

SMTPAuthenticationError at /accounts/register/<br>
(535, '5.7.0 Error: authentication failed: authentication failure')

Environment:

Request Method: POST
Request URL: mywebsite.com/accounts/register/

Django Version: 1.4.1
Python Version: 2.7.3
Installed Applications:
('django.contrib.admin',
 'django.contrib.admindocs',
 'django.contrib.auth',
 'django.contrib.contenttypes',
 'django.contrib.humanize',
 'django.contrib.messages',
 'django.contrib.sessions',
 'django.contrib.sites',
 'django.contrib.staticfiles',
 'registration')
Installed Middleware:
('django.middleware.common.CommonMiddleware',
 'django.contrib.sessions.middleware.SessionMiddleware',
 'django.middleware.csrf.CsrfViewMiddleware',
 'django.contrib.auth.middleware.AuthenticationMiddleware',
 'django.contrib.messages.middleware.MessageMiddleware')


Traceback:
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/core/handlers/base.py" in get_response
  111.                         response = callback(request, *callback_args, **callback_kwargs)
File "build/bdist.linux-x86_64/egg/registration/views.py" in register
  187.             new_user = backend.register(request, **form.cleaned_data)
File "build/bdist.linux-x86_64/egg/registration/backends/default/__init__.py" in register
  79.                                                                     password, site)
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/db/transaction.py" in inner
  209.                 return func(*args, **kwargs)
File "build/bdist.linux-x86_64/egg/registration/models.py" in create_inactive_user
  85.             registration_profile.send_activation_email(site)
File "build/bdist.linux-x86_64/egg/registration/models.py" in send_activation_email
  264.         self.user.email_user(subject, message, settings.DEFAULT_FROM_EMAIL)
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/contrib/auth/models.py" in email_user
  374.         send_mail(subject, message, from_email, [self.email])
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/core/mail/__init__.py" in send_mail
  61.                         connection=connection).send()
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/core/mail/message.py" in send
  248.         return self.get_connection(fail_silently).send_messages([self])
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/core/mail/backends/smtp.py" in send_messages
  85.             new_conn_created = self.open()
File "/home/fireflyltd/webapps/foster/lib/python2.7/django/core/mail/backends/smtp.py" in open
  54.                 self.connection.login(self.username, self.password)
File "/usr/local/lib/python2.7/smtplib.py" in login
  613.             raise SMTPAuthenticationError(code, resp)

Exception Type: SMTPAuthenticationError at /accounts/register/
Exception Value: (535, '5.7.0 Error: authentication failed: authentication failure')
4

2 回答 2

6

您需要将 SMTP 服务器设置添加到settings.py文件中。例子:

EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'mailer@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True

来自 Django文档

使用 EMAIL_HOST 和 EMAIL_PORT 设置中指定的 SMTP 主机和端口发送邮件。EMAIL_HOST_USER 和 EMAIL_HOST_PASSWORD 设置(如果设置)用于对 SMTP 服务器进行身份验证,EMAIL_USE_TLS 设置控制是否使用安全连接。

于 2012-11-13T22:59:50.363 回答
3

为您在此处用作 EMAIL_HOST 的 gmail 帐户设置允许 lesssecureapps https://myaccount.google.com/lesssecureapps
以及 settings.py 中的此设置

EMAIL_HOST = 'smtp.example.com'
EMAIL_PORT = 25
EMAIL_HOST_USER = 'mailer@example.com'
EMAIL_HOST_PASSWORD = 'password'
EMAIL_USE_TLS = True
于 2018-03-16T18:11:23.377 回答