首页 新闻 会员 周边

django 发送邮件重置密码

0
悬赏园豆:80 [已解决问题] 解决于 2016-03-19 10:29

我这个邮件发送功能还没实现,下面代码有点问题正在调试,不过基本代码如下,请问如何通过发送的这封邮件,要写什么才能实现邮件里面点击发送过去的链接更改密码的功能?

用户,密码保存在user_profile表当中

在view当中:

def send_mail(request):
    try:
        subject = 'hello'
        html_content = u'<b>激活链接:</b><a href="http://www.baidu.com">http:www.baidu.com</a>'
        msg = EmailMessage(subject,html_content,EMAIL_HOST_USER,['qq1183534511@sina.com',])
        msg.content_subtype = 'html'
        msg.send()
        return(request,'common/resetpassword.html',locals())
    except Exception as e:
        logger.error(e)
    return render(request,'common/error.html',{'error':e})

在settings当中

#邮件配置
EMAIL_HOST = 'smtp.sina.com'
EMAIL_PORT = '25'
EMAIL_HOST_USER = aaa@sina.com'
EMAIL_HOST_PASSWORD = aaa'
EMAIL_USE_TLS = True
意发并行的主页 意发并行 | 初学一级 | 园豆:3
提问于:2016-03-01 10:38
< >
分享
最佳答案
0
  1. 开发重置密码功能页面
  2. 在连接中加入重置密码功能页面+一个随机字符串(保证唯一,且复杂),并保存这个字符串也邮箱信息
  3. 验证随机字符串与邮箱是否是同一个
  4. 验证通过后可以修改密码
收获园豆:80
刘宏玺 | 专家六级 |园豆:14020 | 2016-03-01 10:50
def send_mail(request):
    try:
        if request.method == 'POST':
            email = request.POST.get('email',None)
            try:
                mail = UserProfile.objects.get(email = email)
            except Exception as e:
                logger.error(e)
                return render(request,'common/error.html',{'error':e})
            subject = 'hello'
            html_content = u'<b>激活链接:</b><a href="http://127.0.0.1:8000/users/send_maiil/">修改密码</a>'
            msg = EmailMessage(subject,html_content,EMAIL_HOST_USER,[email,])
            msg.content_subtype = 'html'
            msg.send()
        return render(request,'common/resetpassword.html',locals())
    except Exception as e:
        logger.error(e)
        return render(request,'common/error.html',{'error':e})

请问如何传入这个随机字符串

html_content = u'<b>激活链接:</b><a href="http://127.0.0.1:8000/users/send_maiil/">修改密码</a>'

我将这个传入字符串用+加号拼接起来结果出错了,请问应该怎样将参数出入进去

意发并行 | 园豆:3 (初学一级) | 2016-03-01 23:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册