Exemplo n.º 1
0
def cms_send_email(request):
    if request.method=='POST':
        form=cf.CMSMailForm(request.POST)
        form.set_request(request)

        if not form.is_valid():
            return xtjson.json_params_error(message=form.get_error())
        else:
            to_mail=form.cleaned_data.get('email')
            mail=send_mail(to_email=to_mail)

            if mail:
                return xtjson.json_result(message='邮件发送成功!')
            else:
                return xtjson.json_server_error(message='请检查邮箱后再试')
Exemplo n.º 2
0
def mail_captcha():
    email = flask.request.args.get('email')
    if xtcache.get(email):
        return xtjson.json_params_error(u'该邮箱已经发送验证码了!')

    source = list(string.letters)
    for x in xrange(0, 10):
        source.append(str(x))
    captcha_list = random.sample(source, 4)
    captcha = ''.join(captcha_list)
    if xtmail.send_mail(subject=u'潭州Python学院邮件验证码',
                        receivers=email,
                        body=u'邮箱验证码是:' + captcha):
        xtcache.set(email, captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_server_error()
Exemplo n.º 3
0
def mail_captcha():
    # mail_captcha/[email protected]/
    # 查询字符串 /mail_captcha/[email protected]
    email = flask.request.args.get('email')

    if xtcache.get(email):
        return xtjson.json_params_error(message=u'该邮箱已经发送验证码了!')

    source = list(string.letters)
    for x in xrange(0, 10):
        source.append(str(x))
    captcha_list = random.sample(source, 4)
    captcha = ''.join(captcha_list)

    if xtmail.send_mail(subject=u'周杰伦发来的邮箱验证码', receivers=email, body=u'邮箱验证码是:'+captcha):
        # 为了下次可以验证邮箱和验证码
        # 为了防止用户不断的刷新这个接口
        xtcache.set(email, captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_params_error(message=u'服务器错误')
Exemplo n.º 4
0
def mail_captcha():
    # /mail_captcha/[email protected]/
    # /mail_captcha/[email protected]
    email = flask.request.args.get('email')

    if xtcache.get(email):
        return xtjson.json_params_error(u'该邮箱已经发送验证码了!')

    source = list(string.ascii_letters)
    for x in range(0, 10):
        source.append(str(x))
    captcha_list = random.sample(source, 4)
    captcha = ''.join(captcha_list)

    if xtmail.send_mail(subject=u'知了课堂Python学院邮件验证码',
                        receivers=email,
                        body=u'邮箱验证码是:' + captcha):
        # 1. 为了下次可以验证邮箱和验证码
        # 2. 为了防止用户不断的刷这个接口
        xtcache.set(email, captcha)
        return xtjson.json_result()
    else:
        return xtjson.json_server_error()
Exemplo n.º 5
0
def celery_send_mail(subject, receivers, body=None, html=None):
    with app.app_context():
        xtmail.send_mail(subject, receivers, body, html)
Exemplo n.º 6
0
def celery_send_email(subject, receivers, body=None, html=None):
    with app.app_context():
        return send_mail(subject=subject,
                         receivers=receivers,
                         body=body,
                         html=html)