Beispiel #1
0
def send_email(email, send_type=0):
    """
		发送邮件
		@email 邮件发送人
		@send_type 0为注册激活, 1为忘记密码
	"""

    email_record = EmailVerifyRecord()
    random_code = random_str()

    email_record.email = email
    email_record.code = random_code
    email_record.send_type = send_type
    email_record.save()

    if send_type == 0:
        eamil_title = u"欢迎注册"
        a_href = u"{0}/account/active/{1}".format(settings.LOCALHOST,
                                                  random_code)
        eamil_body = u"<a href='{0}'>欢迎注册 请点击下面的连接进行激活</a>".format(a_href)
    elif send_type == 1:
        eamil_title = u"忘记密码"
        a_href = u"{0}/account/modify_password/{1}".format(
            settings.LOCALHOST, random_code)
        eamil_body = u"<a href='{0}'>请点击下面的链接修改密码</a>".format(a_href)

    status = django_send_mail(eamil_title,
                              '',
                              settings.EMAIL_FROM, [email],
                              html_message=eamil_body)
    print status
    return status
Beispiel #2
0
def send_register_email(email, send_type="register"):

    EMAIL_FROM = '*****@*****.**'
    HOST = '192.168.1.153:8080'

    email_record = EmailVerifyRecord()
    code = generate_random_string(random_length=16)
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()
    # send email to register
    if send_type == 'register':
        email_title = 'DjangoX注册激活链接'
        email_body = '请点击下面的链接激活你的帐号:{0}{1}{2}'.format(
            'http://' + HOST + '/active/', code, '/')
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
    # send email to reset password
    elif send_type == 'forget':
        email_title = 'DjangoX密码重置链接'
        email_body = '请点击下面的链接重置你的密码:{0}{1}{2}'.format(
            'http://' + HOST + '/reset/', code, '/')
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
Beispiel #3
0
def send_register_email(email, send_type='register'):
    '''发送注册邮件函数'''
    email_record = EmailVerifyRecord()
    if send_type == "update_email":
        code = random_str(4)
    else:
        code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()
    # 先把邮件保存到数据库,然后发送邮件给用户

    email_title = ""
    email_body = ""

    if send_type == "register":
        email_title = "mooc在线注册激活链接"
        email_body = "请点击下面的链接激活你的账号:http://127.0.0.1:8000/" \
                     "active/{0}".format(email_record.code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            print(send_status)  # 1
    elif send_type == "forget":
        email_title = "mooc在线密码重置"
        email_body = "请点击下面的链接激活你的账号:http://127.0.0.1:8000/" \
                     "reset/{0}".format(email_record.code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])

    elif send_type == "update_email":
        email_title = "mooc在线修改邮箱验证码"
        email_body = "你的邮箱验证码为:{0}".format(email_record.code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
Beispiel #4
0
    def _action(self, serializer):
        code = public_fun.randomCode(4)
        record = EmailVerifyRecord()
        record.code = code
        record.email = serializer.data['email']
        record.type = serializer.data['type']
        record.save()
        if public_fun.send_email_code(serializer.data['email'], code):
            return Response(status=status.HTTP_200_OK)

        return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR)
Beispiel #5
0
def send_register_email(email):
    email_record = EmailVerifyRecord()
    code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.save()
    email_title = "注册激活链接"
    email_body = "请点击下面的链接激活你的账号:http://127.0.0.1:8080/account/activate/{0}".format(
        code)
    print(settings.EMAIL_HOST_USER)
    print(type(email))
    print(email)
    send_status = send_mail(email_title, email_body, settings.EMAIL_HOST_USER,
                            [email])
    if send_status:
        pass
Beispiel #6
0
def send_email(email):
    email_record = EmailVerifyRecord()

    code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.save()
    email_titile = '小熊的网站密码重置链接'
    email_body = '请点击下面的链接激活你的账号:http:127.0.0.1:8000/account/reset/{0}'.format(
        code)
    send_status = send_mail(subject=email_titile,
                            message=email_body,
                            from_email=EMAIL_FROM,
                            recipient_list=[email])
    if send_status:
        pass
Beispiel #7
0
def send_register_email(email, send_type='register'):
    email_record = EmailVerifyRecord()
    if send_type == 'update':
        code = random_str(4)
    else:
        code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    email_title = ''
    email_body = ''
    if send_type == 'register':
        email_title = '工大在线注册激活链接'
        email_body = '请点击下面的链接激活账户:http://127.0.0.1:8000/active/{0}'.format(
            code)

        send_status = send_mail(email_title,
                                email_body,
                                DEFAULT_FROM_EMAIL, [email],
                                connection=None)
        if send_status:
            pass
    elif send_type == 'forget':
        email_title = '工大在线重置密码链接'
        email_body = '请点击下面的链接重置密码:http://127.0.0.1:8000/reset/{0}'.format(
            code)

        send_status = send_mail(email_title, email_body, DEFAULT_FROM_EMAIL,
                                [email])
        if send_status:
            pass
    elif send_type == 'update':
        email_title = '工大在线邮箱修改验证码'
        email_body = '您的邮箱验证码为:{0}'.format(code)

        send_status = send_mail(email_title, email_body, DEFAULT_FROM_EMAIL,
                                [email])
        if send_status:
            pass
Beispiel #8
0
def send_register_email(email, send_type="register"):
    email_record = EmailVerifyRecord()
    code = random_str(16)
    email_record.code = code
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    email_title = ""
    email_body = ""

    if send_type == "register":
        email_titlse = "独景网邮箱激活"
        email_body = "感谢您在我站注册了新帐号。请点击链接激活您的帐号。http://127.0.0.1:8000/active/{0}".format(
            code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
    elif send_type == "forget":
        email_title = "独景网密码重置"
        email_body = "请点击以下链接重置密码。http://127.0.0.1:8000/reset/{0}".format(code)
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass
Beispiel #9
0
def send_control_email(email, send_type="register", **kwargs):
    # 初始化为空
    email_title = ""
    email_body = ""
    # 如果为注册类型
    if send_type == "register":
        email_record = EmailVerifyRecord()
        # 将给用户发的信息保存在数据库中
        code = random_str(10)
        email_record.code = code
        email_record.email = email
        email_record.send_type = send_type
        email_record.save()
        # email_title = "你好"
        # email_body = "明天请参会"
        email_title = "沪牌一号注册激活链接"
        if DEBUG:
            email_body = "您在注册沪牌一号的账号,请点击下面的链接激活你的账号: http://127.0.0.1:8000/account/active/{0}/".format(
                code)
        else:
            email_body = "您在注册沪牌一号的账号,请点击下面的链接激活你的账号: https://hupai.pro/account/active/{0}/".format(
                code)
        # 发送邮件
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass

    elif send_type == "forget":
        code = random_num(6)  # 纯数字验证码
        email_record = EmailVerifyRecord.objects.filter(email=email)[0]
        if not email_record:
            email_record = EmailVerifyRecord()
        email_record.code = code
        email_record.send_type = 'forget'
        email_record.save()
        email_title = "沪牌一号找回密码"
        email_body = "您在找回沪牌一号的密码,验证码为: {0}".format(code)
        # 发送邮件
        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
        if send_status:
            pass