Flask项目中如何高效实现邮箱模块功能?
- 内容介绍
- 文章标签
- 相关推荐
本文共计248个文字,预计阅读时间需要1分钟。
在Flask项目中使用邮箱模块的应用示例:pythonfrom flask import Flask, render_template, make_responsefrom flask_mail import Mail, Messageimport osimport datetimefrom flask_script import Manager
app=Flask(__name__)app.config['MAIL_SERVER']='smtp.qq.com'
mail=Mail(app)manager=Manager(app)
def send_email(subject, to, template, **kwargs): msg=Message(subject, recipients=[to]) msg.body=render_template(template, **kwargs) msg.=msg.body mail.send(msg)
if __name__=='__main__': manager.run()
Flask项目中邮箱模块的应用
from flask import Flask, render_template, make_response from flask_mail import Mail, Message import os import datetime from flask_script import Manager app = Flask(__name__) app.config['MAIL_SERVER'] = 'smtp.qq.com' app.config['MAIL_PORT'] = 465 app.config['MAIL_USE_TLS'] = False app.config['MAIL_USE_SSL'] = True app.config['MAIL_USERNAME'] = '[emailprotected]' app.config['MAIL_PASSWORD'] = 'bjqvxyuexkgnhccc' app.config['FLASK_MAIL_SUBJECT_PREFIX'] = '[Flasky]' app.config['MAIL_DEFAULT_SENDER'] = '[emailprotected]' 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 = '[emailprotected]' subject = '自查信息包括问题单/事件单/变更单等' send_email(recipter, subject) return make_response('secceess') if __name__ == '__main__': manager.run()
本文共计248个文字,预计阅读时间需要1分钟。
在Flask项目中使用邮箱模块的应用示例:pythonfrom flask import Flask, render_template, make_responsefrom flask_mail import Mail, Messageimport osimport datetimefrom flask_script import Manager
app=Flask(__name__)app.config['MAIL_SERVER']='smtp.qq.com'
mail=Mail(app)manager=Manager(app)
def send_email(subject, to, template, **kwargs): msg=Message(subject, recipients=[to]) msg.body=render_template(template, **kwargs) msg.=msg.body mail.send(msg)
if __name__=='__main__': manager.run()
Flask项目中邮箱模块的应用
from flask import Flask, render_template, make_response from flask_mail import Mail, Message import os import datetime from flask_script import Manager app = Flask(__name__) app.config['MAIL_SERVER'] = 'smtp.qq.com' app.config['MAIL_PORT'] = 465 app.config['MAIL_USE_TLS'] = False app.config['MAIL_USE_SSL'] = True app.config['MAIL_USERNAME'] = '[emailprotected]' app.config['MAIL_PASSWORD'] = 'bjqvxyuexkgnhccc' app.config['FLASK_MAIL_SUBJECT_PREFIX'] = '[Flasky]' app.config['MAIL_DEFAULT_SENDER'] = '[emailprotected]' 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 = '[emailprotected]' subject = '自查信息包括问题单/事件单/变更单等' send_email(recipter, subject) return make_response('secceess') if __name__ == '__main__': manager.run()

