예제 #1
0
def send_password_email(email):
    email_record = EmailVerifyCode()
    code = ''.join(random.sample(string.ascii_letters + string.digits, 20))  # 注册获取16位长度的字符
    email_record.code = code  # 验证码
    email_record.email = email  # 邮箱
    email_record.save()  # 保存到数据库中
    nick_name = UserProfile.objects.get(email=email).nick_name
    email_title = "{0} - 重置密码".format(nick_name)
    email_body = "请点击下面的链接重置你的密码:http://127.0.0.1:8000/password?code={0}".format(code)
    send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
    return send_status
예제 #2
0
def send_mail_code(email, send_type):
    ## 1.创建邮箱验证码对象,保存数据,用以后作对比
    emailVerifyCode = EmailVerifyCode()
    emailVerifyCode.email = email
    emailVerifyCode.send_type = send_type
    # 获取验证码
    code = get_random_code(8)
    emailVerifyCode.code = code
    emailVerifyCode.save()

    ## 2.settings.py配置信息
    # EMAIL_HOST = 'smtp.163.com'                      # smpt服务地址
    # EMAIL_PORT = 25                                  # 端口号
    # EMAIL_HOST_USER = '******'       # 发送邮件的邮箱地址即发件人
    # EMAIL_HOST_PASSWORD = '******'          # 发送邮件的邮箱[即发件人]中设置的客户端授权密码
    # EMAIL_FROM = '谷粒教育<*****@*****.**>'  # 收件人看到的发件人

    ## 3.发送邮件的具体内容信息
    # 激活用户
    if send_type == 1:
        send_title = "欢迎注册谷粒教育网站:"
        send_body = "请点击以下链接,进行激活账号: \n http://127.0.0.1:8000/users/user_active/" + code
        # 发送邮件
        send_mail(send_title, send_body, settings.EMAIL_FROM, [email])

    # 重置密码
    if send_type == 2:
        send_title = "谷粒教育重置密码系统:"
        send_body = "请点击以下链接,进行重置密码: \n http://127.0.0.1:8000/users/user_reset/" + code
        # 发送邮件
        send_mail(send_title, send_body, settings.EMAIL_FROM, [email])

    # 修改邮箱-获取验证码
    if send_type == 3:
        send_title = "谷粒教育重置邮箱验证码:"
        send_body = "你的邮箱验证码是: " + code
        # 发送邮件
        send_mail(send_title, send_body, settings.EMAIL_FROM, [email])
예제 #3
0
def send_email_code(email, send_type):
    # 第一步:创建邮箱验证码对象,保存至数据库,用来以后做对比
    code = get_uuid()
    a = EmailVerifyCode()
    a.email = email
    a.send_type = send_type
    a.code = code
    a.save()
    # 第二步:发送邮件
    send_title = ''
    send_body = ''
    if send_type == 1:
        send_title = '欢迎注册谷粒教育网站'
        send_body = '请点击以下链接进行激活您的账号:\n http://127.0.0.1:8000/users/user_active/' + str(
            code)
        try:
            send_mail(send_title, send_body, EMAIL_FROM, [email])
            return True
        except:
            return False
    if send_type == 2:
        send_title = '谷粒教育重置密码'
        send_body = '请点击以下链接进行重置您的账号密码:\n http://127.0.0.1:8000/users/user_reset/' + str(
            code)
        try:
            send_mail(send_title, send_body, EMAIL_FROM, [email])
            return True
        except:
            return False
    if send_type == 3:
        send_title = '重新绑定邮箱'
        send_body = '验证码:\n' + str(code)
        try:
            send_mail(send_title, send_body, EMAIL_FROM, [email])
            return True
        except:
            return False
예제 #4
0
def send_email(email, send_type='register'):
    ###########################生成随机验证码存入数据库中###########################
    #继承模型
    email_record = EmailVerifyCode()
    if send_type == 'update':
        code = random_str(4)  #如果是更新邮箱则发送4位验证码
    else:
        code = random_str(16)
    #将随机生成code存入数据库中
    email_record.code = code
    #将管理的邮箱传入数据库中
    email_record.email = email
    #定义发送类型
    email_record.send_type = send_type
    email_record.save()

    ###########################发送激活邮件###########################
    email_title = ''
    email_body = ''
    receive_email = email

    if send_type == 'register':
        email_title = '慕学在线激活连接'
        email_body = '请点击下方连接,激活注册:' + 'http://127.0.0.1:8000/active/{0}'.format(
            code)

    if send_type == 'find_password':
        email_title = '慕学在线密码找回连接'
        email_body = '请点击下方连接,进行密码找回:' + 'http://127.0.0.1:8000/password_reset/{0}'.format(
            code)

    if send_type == 'update':
        email_title = '慕学在线更新邮箱的验证码'
        email_body = '更新邮箱的验证码是:' + code

    send_status = send_mail(email_title, email_body, EMAIL_FROM,
                            [receive_email])
예제 #5
0
def send_email_code(email,send_type):
    '''这是发送邮箱验证码的函数'''
    #第一步:创建验证码,存到数据库,后面用来比对
    code=get_random_code(8)
    evc=EmailVerifyCode()
    evc.email=email
    evc.send_type=send_type
    evc.code=code
    evc.save()
    #第二步:发邮件
    send_title=''
    send_body=''
    if send_type==1:
        send_title='欢迎注册谷粒教育'
        send_body='请点击以下链接激活您的账号:\nhttp://127.0.0.1:8000/users/user_active/'+code
        send_mail(send_title,send_body,EMAIL_FROM,[email])
    if send_type==2:
        send_title='谷粒教育重置密码'
        send_body='请点击以下链接重置您的密码:\nhttp://127.0.0.1:8000/users/user_reset/'+code
        send_mail(send_title,send_body,EMAIL_FROM,[email])
    if send_type==3:
        send_title='谷粒教育修改邮箱验证码'
        send_body='下面是您的验证码(5分钟内有效):\n'+code
        send_mail(send_title,send_body,EMAIL_FROM,[email])
예제 #6
0
def send_mail_code(email, type):
    a = EmailVerifyCode()
    a.email = email
    a.send_type = type
    a.code = get_random_code(6)