#! /usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright(C), 2019, <NAME>.
#
# Author:       zhang
# DATE:         2019/5/24 15:42
# IDE_NAME:     PyCharm
# Filename:     email_send.py
# Version:      1.0.0
# Description:  
# History:       
import random

from django.core.mail import send_mail
from users.models import EmailVerifyRecord
from MxOnline.settings import EMAIL_FROM

def generate_random_str(length=8):
    str = ''
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'
    leng = len(chars)
    for i in range(length):
        str += chars[random.randint(0, leng-1)]
    return str


def send_register_email(email, send_type="register", code_length=16):
    email_record = EmailVerifyRecord()
    email_record.code = generate_random_str(code_length)
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    if send_type == "register":
        email_title = "慕学在线网激活邮件"
        email_content = "请点击如下连接激活您的账户：http://127.0.0.1:8000/active/{0}".format(email_record.code)

        send_status = send_mail(email_title, email_content,EMAIL_FROM, [email])
        if send_status:
            pass
    elif send_type == "reset":
        email_title = "慕学在线网重置密码邮件"
        email_content = "请点击如下连接重新设置您的密码：http://127.0.0.1:8000/reset/{0}".format(email_record.code)

        send_status = send_mail(email_title, email_content, EMAIL_FROM, [email])
        if send_status:
            pass

    elif send_type == "update_email":
        email_title = "慕学在线网更新注册邮箱邮件"
        email_content = "您正在申请更新慕学在线网的注册邮箱为此邮箱，验证码为：{0}".format(email_record.code)

        send_status = send_mail(email_title, email_content, EMAIL_FROM, [email])
        if send_status:
            pass
#! /usr/bin/env python
# -*- coding: UTF-8 -*-

# Copyright(C), 2019, <NAME>.
#
# Author:       zhang
# DATE:         2019/5/24 15:42
# IDE_NAME:     PyCharm
# Filename:     email_send.py
# Version:      1.0.0
# Description:  
# History:       
import random

from django.core.mail import send_mail
from users.models import EmailVerifyRecord
from MxOnline.settings import EMAIL_FROM

def generate_random_str(length=8):
    str = ''
    chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890'
    leng = len(chars)
    for i in range(length):
        str += chars[random.randint(0, leng-1)]
    return str


def send_register_email(email, send_type="register", code_length=16):
    email_record = EmailVerifyRecord()
    email_record.code = generate_random_str(code_length)
    email_record.email = email
    email_record.send_type = send_type
    email_record.save()

    if send_type == "register":
        email_title = "慕学在线网激活邮件"
        email_content = "请点击如下连接激活您的账户：http://127.0.0.1:8000/active/{0}".format(email_record.code)

        send_status = send_mail(email_title, email_content,EMAIL_FROM, [email])
        if send_status:
            pass
    elif send_type == "reset":
        email_title = "慕学在线网重置密码邮件"
        email_content = "请点击如下连接重新设置您的密码：http://127.0.0.1:8000/reset/{0}".format(email_record.code)

        send_status = send_mail(email_title, email_content, EMAIL_FROM, [email])
        if send_status:
            pass

    elif send_type == "update_email":
        email_title = "慕学在线网更新注册邮箱邮件"
        email_content = "您正在申请更新慕学在线网的注册邮箱为此邮箱，验证码为：{0}".format(email_record.code)

        send_status = send_mail(email_title, email_content, EMAIL_FROM, [email])
        if send_status:
            pass
#! /usr/bin/env python # -*- coding: UTF-8 -*- # Copyright(C), 2019, <NAME>. # # Author:       zhang # DATE:         2019/5/24 15:42 # IDE_NAME:     PyCharm # Filename:     email_send.py # Version:      1.0.0 # Description: # History: