Flask邮箱认证以及头像
from threading import Thread from flask import current_app, render_template from flask.ext.mail import Message from Main import mail def send_async_email(app, msg): with app.app_context(): mail.send(msg) def send_email(to, subject, template, **kwargs): app = current_app._get_current_object() msg = Message(app.config[\'FLASKY_MAIL_SUBJECT_PREFIX\'] + \' \' + subject, sender=app.config[\'FLASKY_MAIL_SENDER\'], recipients=[to]) msg.body = render_template(template + \'.txt\', **kwargs) msg.html = render_template(template + \'.html\', **kwargs) thr = Thread(target=send_async_email, args=[app, msg]) thr.start() return thr 邮箱的配置:
创新互联公司专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、成都网站建设、外贸网站建设、仁寿网络推广、成都微信小程序、仁寿网络营销、仁寿企业策划、仁寿品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们大的嘉奖;创新互联公司为所有大学生创业者提供仁寿建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.comapp.config[\'MAIL_DEBUG\'] = True # 开启debug,便于调试看信息 app.config[\'MAIL_SUPPRESS_SEND\'] = False # 发送邮件,为True则不发送 app.config[\'MAIL_SERVER\'] = \'smtp.qq.com\' # 邮箱服务器 app.config[\'MAIL_PORT\'] = 465 # 端口 app.config[\'MAIL_USE_SSL\'] = True # 重要,qq邮箱需要使用SSL app.config[\'MAIL_USE_TLS\'] = False # 不需要使用TLS app.config[\'MAIL_USERNAME\'] = \'xxxxxx@qq.com\' # 填邮箱 app.config[\'MAIL_PASSWORD\'] = \'zzzzzzz\' # 填授权码 app.config[\'MAIL_DEFAULT_SENDER\'] = \'xxxxxxxxxxxx@qq.com\' # 填邮箱,默认发送者 app.config[\'FLASKY_MAIL_SUBJECT_PREFIX\']=\'[blog]\' app.config[\'FLASKY_MAIL_SENDER\']=\'xxxxxxxxxxx@qq.com\' 头像功能通过avatar实现
def gravatar(self, size=100, default=\'identicon\', rating=\'g\'): if request.is_secure: url = \'https://secure.gravatar.com/avatar\' else: url = \'http://www.gravatar.com/avatar\' hash = self.avatar_hash or hashlib.md5( self.email.encode(\'utf-8\')).hexdigest() return \'{url}/{hash}?s={size}&d={default}&r={rating}\'.format( url=url, hash=hash, size=size, default=default, rating=rating) 根据用户邮箱生成对应的hash码发送到avatar网站即可生成头像
分享标题:Flask邮箱认证以及头像
标题网址:http://azwzsj.com/article/chedse.html