Exemple #1
0
def send_email():
    # message = Message(subject='this is first mail.', recipients=['*****@*****.**'], body='this is content.')
    message = Message(subject='this is first mail.',
                      recipients=['*****@*****.**'],
                      body='this is content.')
    mail.send(message)
    return 'success.'
Exemple #2
0
def test_email():
    message = Message(subject='测试邮件',html='<h1>这是封测试文件</h1><a href="www.baidu.com">点开连接</a>',recipients=['*****@*****.**'])
    try:
        mail.send(message)
        return '发送成功!'
    except Exception as e:
        return str(e)
Exemple #3
0
def email_captcha():
    email = request.args.get('email')
    if not email:
        return xjson.json_paramserror('请传递邮箱地址')

    #生成6位数的随机验证码
    source = list(string.ascii_letters)
    source.extend(map(lambda x:str(x),range(0,10)))
    captcha = ''.join(random.sample(source,6))

    #发送验证码邮件
    msg = Message('Aroma的BBS论坛更换邮箱验证码',
                  recipients=[email],
                  body='您的验证码是:{},5分钟内有效'.format(captcha)
                  )
    try:
        mail.send(msg)
    except Exception as err:
        print(err)
        return xjson.json_servererror(message='邮件发送失败')

    # 验证码存入memcache
    print(email+'*'*10+captcha)
    xcache.set(email, captcha)
    return xjson.json_success(message='邮件发送成功')
Exemple #4
0
def email_captcha():
    #/cms/email_capthcha/[email protected]
    email = request.args.get('email')
    print(email)
    if not email:
        return xjson.json_params_error('请传递邮件参数!')

    #生成6位数的随机验证码
    source = list(string.ascii_letters)
    source.extend(map(lambda x: str(x), range(0, 10)))
    captcha = ''.join(random.sample(source, 6))

    #发送邮件
    msg = Message('BBS论坛更换邮箱验证码',
                  recipients=[email],
                  body='您的验证码:{},5分钟内邮箱'.format(captcha))
    try:
        mail.send(msg)
    except Exception as err:
        print(err)
        return xjson.json_server_error(message='邮件发送失败')

    #验证码存入memcached
    xcache.set(email, captcha)
    return xjson.json_sucess(message='邮件发送成功')
Exemple #5
0
def async_send_mail(msg):
    '''异步发送邮件'''
    # 在使用到的时候再导入app,在头部导入会出错
    from app import app
    # 创建应用上下文
    with app.app_context():
        mail.send(message=msg)
Exemple #6
0
def email_captcha():
    email = request.args.get('email')
    params = request.referrer.split('/')[-2]
    print(email)
    print(params)
    regex = '^[A-Za-z\d]+([-_.][A-Za-z\d]+)*@([A-Za-z\d]+[-.])+[A-Za-z\d]{2,4}$'
    if not re.match(regex, email):
        return restful.params_error('请输入正确格式的邮箱!')
    if not email:
        return restful.params_error('请传递邮箱参数!')
    elif params == 'signup' and User.objects(email=email).first():
        return restful.params_error('邮箱已经被注册,请更换邮箱!')
    elif User.objects(email=email).first() and (params == 'resetpwd'
                                                or params == 'resetmail'):
        return restful.params_error('该邮箱已经被注册,请更换邮箱!')
    else:
        source = list(string.ascii_letters)
        source.extend(map(lambda x: str(x), range(0, 10)))
        captcha = "".join(random.sample(source, 6))
        print(captcha)
        message = Message('专家值守平台邮箱验证码',
                          recipients=[email],
                          body='您的验证码是:{}'.format(captcha))
        print(message)
    try:
        mail.send(message)
    except Exception as e:
        return restful.server_error(message='可能邮箱不存在!请检查后再试')
    zlcache.set(email, captcha)
    return restful.success()
Exemple #7
0
def send_mail(subject, recipients, captcha, username, operate):
    message = Message(subject, recipients)
    message.html = render_template('common/sendemail.html',
                                   captcha=captcha,
                                   username=username,
                                   operate=operate)
    mail.send(message)
def test():
    mail = Mail(app)
    message = Message(subject=u'知了课堂Python学院邮件验证码',
                      recipients=['*****@*****.**'],
                      body='abcd')
    mail.send(message)
    return 'success'
Exemple #9
0
def send_email():
    message = Message("验证码",recipients=['*****@*****.**'],body="测试")
    try:
        mail.send(message)
    except Exception as e:
        server_error(msg=e)
    return "邮件发送成功"
Exemple #10
0
def email_captcha():
    """
    发送邮件我们不需要跳转页面,不需要重定向;邮件地址信息只需通过get方式请求即可
    后台获取邮件信息需要进行相关的判断,没有通过验证就将信息(状态码,信息)发送到前端页面(js文件处理)
    通过验证,我们需要自制验证码,将验证码发送到接收者邮件,并且以邮件地址为键,验证码为值保存到redis缓存中
    :return:
    """
    # /email_captcha/[email protected]
    email = request.args.get("email")
    if not email:
        return restful.params_error("请输入邮箱地址")

    # 获取所有的字母(大小写)并且转换成列表
    source = list(string.ascii_letters)
    # 再次获取数字,并且拼接到source中
    source.extend(map(lambda x: str(x), range(0, 10)))

    # 从source中随机取样返回的是一个列表,通过join方式将其变成字符串作为验证码
    captcha = "".join(random.sample(source, 6))
    # 定义一个信息类实例,传递邮件标题,邮件接收者,邮件内容
    message = Message("校园论坛邮箱验证码", recipients=[email], body="您的验证码是:%s" % captcha)
    try:
        # 通过邮件类实例发送上面封装的信息类实例
        mail.send(message)
    except:
        return restful.server_error()

    # 将邮件保存到redis数据库中(修改邮箱通过在redis缓存中取出验证码)
    cpcache.set(email, captcha)

    return restful.success()
Exemple #11
0
def send_mail(subject, recipients, body):
    message = Message(subject=subject, recipients=recipients, body=body)
    mail.send(message)


# celery -A task.celery worker --loglevel=info --pool=solo

# pip install eventlet
Exemple #12
0
def test_email():
    msg = Message('Flask项目测试邮件', #邮件主题
                  sender='*****@*****.**', #发送邮箱
                  recipients=['*****@*****.**'], #接收邮箱,这是个列表,可以有多个接收者
                  body='Hello,这是一封测试邮件,这是正文'
                   )
    mail.send(msg)
    return '发送成功'
Exemple #13
0
def send_email():
    message = Message(
        '在线系统邮件发送',
        recipients=['*****@*****.**'],
        body='测试',
    )
    mail.send(message)
    return 'success'
Exemple #14
0
def send_mail(subject, recipients, body):
    message = Message(subject=subject, recipients=recipients, body=body)
    mail.send(message)


# @celery.task
# def send_sms_captcha(telephone,captcha):
#     alidayu.send_sms(telephone,code=captcha)
Exemple #15
0
def rest_email():
    msg = Message(
        'flask测试邮件',
        sender='*****@*****.**',  #发送者
        recipients=['*****@*****.**'],  #  发送给谁,这里是列表可以给多个人发送
        body='hello,  这是一封测试邮件,这是邮件正文')
    mail.send(msg)
    return 'success'
Exemple #16
0
def test_email():
    msg = Message(
        'Flask项目测试邮件',  # 这是邮件主题
        sender='',
        recipients=[''],  # 发送给谁,这是个列表,可以有多个接收者
        body='Hello, 这是一封测试邮件,这是邮件的正文')
    mail.send(msg)  #发送
    return 'success'
Exemple #17
0
def test_email():
    msg = Message(
        'Flask项目测试邮件',  #这是邮件主题
        sender='*****@*****.**',
        recipients=['*****@*****.**'],  #发送给谁,这是个列表,可以有多个接收者
        body='Hello, 这是一封测试邮件,这是邮件的正文')
    mail.send(msg)  #发送
    return 'success'
Exemple #18
0
def test_email():
    msg = Message(
        'Flask项目测试邮件',  # 这是邮件主题
        sender='*****@*****.**',
        recipients=['*****@*****.**'],  # 发送给谁,这是个列表,可以有多个接收者
        body='Hello, 这是一封测试邮件,这是邮件的正文')
    mail.send(msg)  #发送
    return 'success'
Exemple #19
0
def send_email():
    # 1.标题,2.收件人,3.发送的正文内容
    message = Message(subject='derek论坛密码修改邮件发送',
                      recipients=[
                          '*****@*****.**',
                      ],
                      body='第一次测试发送邮件')
    mail.send(message)  # 发送邮件
    return '邮件发送成功'
Exemple #20
0
def send_mail(name, tel, email, kind, question):
    kind_list = ['电商从业合规', '消费者维权', '知识产权保护', '其他']
    body = '姓名:' + name + '\n' + '电话:' + tel + '\n' + '邮件:' + email + '\n' + \
           '种类:' + kind_list[kind - 1] + '\n' + '问题:' + question
    with app.app_context():
        message = Message(subject='千寻科技问题咨询(自动邮件)',
                          recipients=['*****@*****.**'],
                          body=body)
        mail.send(message)
        print('邮件发送成功')
Exemple #21
0
def email_capture():
    email = request.form.get('email')
    print(email)
    source = list(string.ascii_letters)
    source.extend(map(lambda x: str(x), range(0, 10)))
    em_capture = ''.join(random.sample(source, 6))
    print(em_capture)
    message = Message('邮箱验证码', recipients=[email], body='验证码是:%s' % em_capture)
    mail.send(message=message)
    # sendmail.daly('邮箱验证码', recipients=[email], body='验证码是:%s' % em_capture)
    bbs_cache.set(email, em_capture)
    return restful.success('发送成功')
Exemple #22
0
def send_email(subject, sender, recipients, text_body, html_body):
    app = db.app

    with app.app_context():
        msg = Message(subject, sender=sender, recipients=recipients)
        msg.body = text_body
        msg.html = html_body
        try:
            mail.send(msg)
        except Exception as e:
            print(e)
            return field.params_error(message='邮件服务器出错')
Exemple #23
0
def send_mail(subject, receivers, body=None, html=None):
    assert receivers
    if not body and not html:
        return False
    if isinstance(receivers, str) or isinstance(receivers, unicode):
        receivers = [receivers]
    msg = Message(subject=subject, recipients=receivers, body=body, html=html)
    try:
        mail.send(msg)
    except:
        return False
    return True
Exemple #24
0
def email_captcha():
    email = request.args.get('email')
    if not email:
        return restful.params_error('请输入邮箱')
    source = list(string.ascii_letters)
    source.extend(map(lambda x:str(x),range(0,10)))
    captcha =  "".join(random.sample(source,6))
    message = Message('bbs 邮箱验证码',recipients=[email],body='您的验证码是:%s' %captcha)
    try:
        mail.send(message)
    except:
        return restful.server_error()
    cache.set(email,captcha)
    return restful.success()
def email_captcha():
    email = request.args.get('email')
    if not email:
        return 'empty address', 400
    captcha = ''.join(map(str, np.random.randint(0, 10, 6)))
    if cache.get(email):
        return 'request too frequently'
    msg = Message('百团通注册验证码', recipients=[email], body='您的验证码是:%s' % captcha)
    try:
        mail.send(msg)
    except smtplib.SMTPException:
        return 'sending failed', 500
    cache.set(email, captcha)
    return 'success', 200
Exemple #26
0
def email_captcha():
    email = request.args.get("email")
    if not email:
        return restful.params_error("请输入邮箱")
    source = list(string.ascii_letters)
    source.extend(map(lambda x: str(x), range(0, 10)))
    captcha = "".join(random.sample(source, 6))
    zlcache.set(email, captcha)
    message = Message("验证码", [email], "您的验证码是:%s" % captcha)
    try:
        mail.send(message)
    except:
        return restful.server_error()
    return restful.success()
Exemple #27
0
def send_email(subject,receviers,body=None,html=None):
    #断言必须要有接受者
    assert receviers
    #如果发送的邮件没有内容
    if not body and not html:
        return False
    if isinstance(receviers,str) or isinstance(receviers,unicode):
        receviers = [receviers]
    message = Message(subject=subject,recipients=receviers,body=body,html=html)
    try:
        mail.send(message)
    except:
        return False
    return True
Exemple #28
0
def email_captcha():
    # 0. 邮箱验证:正则校验
    # 通过验证:
    email = request.args.get('email')
    import re
    if re.match(
            "^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}| \
            [0-9]{1,3})(\\]?)$", email) is not None:
        # /email_capicha/[email protected] - 通过查询字符串的形式将邮箱传递到后台
        # 1. 查询字符串
        email = request.args.get('email')
        if not email:
            return restful.params_error('请传递邮箱参数!')

        # 2. 产生验证码
        # 2.1 a-zA-Z的字符串
        source = list(string.ascii_letters)

        # 2.2 将一个列表的值更新到另一个列表中,利用list.extend()
        # 方法1
        # source.extend(['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'])

        # 方法2
        # map(func,obj) 将obj(需要可迭代的对象)的数据传递到函数中,然后处理后再返回
        # lambda函数:匿名函数
        # lambda x:str(x) 定义一个匿名函数,变量为x,处理方式为将x传入到str()中,进行字符串转义
        source.extend(map(lambda x: str(x), (range(0, 10))))

        # 2.3 随机采样
        # sample 采样器,从source中随机选择6个,返回值为列表
        list_captcha = random.sample(source, 6)

        # 将字符串转换成列表
        captcha = "".join(list_captcha)

        # 3.给这个邮箱发送邮件
        message = Message('武汉柠檬班论坛邮箱验证码',
                          recipients=[email],
                          body='您的验证码是:%s' % captcha)
        try:
            mail.send(message)
        except Exception as e:
            return restful.server_error()
        # 4. 存验证码,key=email,value=captcha
        zlcache.set(email, captcha)

        return restful.success()
    else:
        return restful.params_error(message='请输入正确的邮箱格式!')
Exemple #29
0
def email_captcha():

    email = request.args.get('email')
    if not email:
        return restful.params_error("请输入邮箱账号")
    source = list(string.ascii_letters)
    source.extend(map(lambda x:str(x),range(0,10)))
    captcha = "".join(random.sample(source,6))

    message = Message("Python论坛邮件验证码",recipients=[email],body="你正在修改Python论坛登录邮箱账号,你的验证码是: %s"%captcha)
    try:
        mail.send(message)
    except:
        return restful.server_error()
    return restful.success()
Exemple #30
0
def send_mail(subject, receivers, body=None, html=None):
    # 必须要有接收者,没有就断言失败
    assert receivers
    # 如果body和html都为空,那么就返回False,因为没有东西可以发送
    if not body and not html:
        return False
    # 如果是字符串,要包裹成数组
    if isinstance(receivers, str) or isinstance(receivers, unicode):
        receivers = [receivers]
    msg = Message(subject=subject, recipients=receivers, body=body, html=html)
    try:
        mail.send(msg)
    except:
        return False
    return True
Exemple #31
0
def send_mail(subject, recipients, body):
    message = Message(subject=subject, recipients=recipients, body=body)
    mail.send(message)
Exemple #32
0
def email():
    message = Message('测试邮件', recipients=['*****@*****.**'], body='测试')
    mail.send(message)
    return '邮件发送成功!'