Django 비밀번호 재설정 메일 보내기

2612 단어 Django
1.seetings.py
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_USE_TLS = False EMAIL_USE_SSL = True EMAIL_HOST = ‘smtp.163.com’ EMAIL_PORT = 465 EMAIL_HOST_USER = ‘[email protected]’ EMAIL_HOST_PASSWORD = ‘XXXXXXXXXXXX’
2.views.py
def sendemail(request):
    emailaddress = request.POST['email']
    if User.objects.filter(email=emailaddress):
        for i in User.objects.filter(email=emailaddress):
            nametemp = i.username
            idtemp = i.id

            #       
            from random import choice
            import string
            # python3  string.ascii_letters, python2      string.letters string.ascii_letters
            def GenPassword(length=8, chars=string.ascii_letters + string.digits):
                return ''.join([choice(chars) for i in range(length)])
            pawdtemp = GenPassword(8)

            User.objects.filter(email=emailaddress).delete()
            User.objects.create_user(id=idtemp, username=nametemp, password=pawdtemp,email=emailaddress)

            from django.core.mail import send_mail
            send_mail(
                subject=u"      ,         ", message=pawdtemp,
                from_email='[email protected]', recipient_list=[emailaddress, ], fail_silently=False,
            )
            return HttpResponse("            ,                 ,        ")
    else:
        return HttpResponse("               ")

좋은 웹페이지 즐겨찾기