コード例 #1
0
ファイル: send_email.py プロジェクト: CannotTell/django_learn
def send_email(email, code_type='register'):

    email_record = EmailVerifyRecord()
    code = random_str(random_len=16)
    email_record.code = code
    email_record.email = email
    email_record.sendType = code_type
    email_record.save()

    send_status = None

    if code_type == 'register':
        email_title = '激活链接'
        email_body = '请点击以下激活链接:http://{}/verifyCode/?type={}&code={}'.format(
                        Site.objects.get_current().domain, code_type, code)

        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])
    elif code_type == 'forget':
        email_title = '重置密码链接'
        email_body = '请点击以下激活链接:http://{}/pwdReset/?type={}&code={}'.format(
            Site.objects.get_current().domain, code_type, code)

        send_status = send_mail(email_title, email_body, EMAIL_FROM, [email])

    return send_status
コード例 #2
0
def sendRegisterEmail(email, sendType="register"):
    emailRecord = EmailVerifyRecord()
    emailRecord.code = generateRandomStr(16)
    emailRecord.email = email
    emailRecord.sendType = sendType
    emailRecord.save()

    emailTitle = ""
    emailBody = ""

    if sendType == "register":
        emailTitle = "onLineLearning website register"
        emailBody = "please click the link to active your account: http://127.0.0.1:8000/active/{0}".format(
            emailRecord.code)
        send_status = send_mail(emailTitle, emailBody, EMAIL_FROM, [email])
        if send_status:
            pass
    elif sendType == "forget":
        emailTitle = "onLineLearning website password reset"
        emailBody = "please click the link to reset your password: http://127.0.0.1:8000/reset/{0}".format(
            emailRecord.code)
        send_status = send_mail(emailTitle, emailBody, EMAIL_FROM, [email])
        if send_status:
            pass