Flask项目中邮箱模块的应用
from flask import Flask,render_template,make_responsefrom flask_mail import Mail,Messageimport osimport datetimefrom flask_script import Managerapp = Flask(__name__)app.config['MAIL_SERVER'] = 'smtp.qq.com'app.config['MAIL_PORT'] = 465app.config['MAIL_USE_TLS'] = Falseapp.config['MAIL_USE_SSL'] = Trueapp.config['MAIL_USERname'] = '[email protected]'app.config['MAIL_PASSWORD'] = 'bjqvxyuexkgnhccc'app.config['FLASK_MAIL_SUBJECT_PREFIX'] = '[Flasky]'app.config['MAIL_DEFAulT_SENDER'] = '[email protected]'mail = Mail(app) # 创建发送邮件对象 用于发送邮件manager = Manager(app)def send_email(to,subject,**kwargs): msg = Message(app.config['FLASK_MAIL_SUBJECT_PREFIX'] + subject,sender=app.config['MAIL_USERname'],recipIEnts=[to],date=datetime.datetime.Now().timestamp()) # msg.body = render_template(template + '.txt',**kwargs) # msg.HTML = render_template(template + '.HTML',**kwargs) print(app.config['MAIL_PASSWORD']) print(app.config['MAIL_USERname']) msg.body = 'text body' msg.HTML = '<b>HTML</b> body' with app.app_context(): mail.send(msg)@app.route('/blog_mail')def index(): recipter = '[email protected]' subject = '自查信息包括问题单/事件单/变更单等' send_email(recipter,subject) return make_response('secceess')if __name__ == '__main__': manager.run()总结
以上是内存溢出为你收集整理的Flask项目中邮箱模块的应用全部内容,希望文章能够帮你解决Flask项目中邮箱模块的应用所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)