我想用我的godaddy邮箱发送邮件。我在views .py中创建的功能,这与gmail帐户完美配合,但不从我的godaddys电子邮件发送电子邮件。请告诉我这里可能犯了什么错误。
views.py(发送验证码的函数)
class SignUp(CreateView):
form_class = UserCreateForm
template_name = 'accounts/signup.html'
def get(self, request, *args, **kwargs):
form = self.form_class()
return render(request, self.template_name, {'form': form})
def post(self, request, *args, **kwargs):
form = self.form_class(request.POST)
if form.is_valid():
user = form.save(commit=False)
user.is_active = False # Deactivate account till it is confirmed
user.save()
current_site = get_current_site(request)
subject = 'Activate Your Dotescrow Account'
html_message = loader.render_to_string('accounts/account_activation_email.html', {
'user': user,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(user.pk)),
'token': account_activation_token.make_token(user),
})
user.email_user(subject,'message' ,fail_silently=True,html_message=html_message)
messages.success(request, 'Please verify you email to activate you account.')
return redirect('accounts:signup')
return render(request, self.template_name, {'form': form})
settings.py
EMAIL_BACKEND = 'django.core.mail.backends.smtp.EmailBackend'
EMAIL_HOST = 'mail.bussicess.net'
EMAIL_HOST_USER = 'no-reply@bussicess.net'
DEFAULT_FROM_EMAIL = EMAIL_HOST_USER
EMAIL_HOST_PASSWORD = 'mypassword'
EMAIL_PORT = 465
EMAIL_USE_SSL = True
EMAIL_USE_TLS = False
如果需要更多的代码,然后在注释会话中告诉我。谢谢你。
这段代码工作得很好,我只是因为网络连接不好而很晚才收到邮件,但是你们可以在django中使用它。这段代码适用于godaddy电子邮件。谢谢你。