50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
from flask import Flask, render_template, jsonify
|
|
from flask_mail import Mail, Message
|
|
import os
|
|
from threading import Thread
|
|
|
|
PEOPLE_FOLDER = os.path.join('static', 'images')
|
|
|
|
app = Flask(__name__)
|
|
app.config['UPLOAD_FOLDER'] = PEOPLE_FOLDER
|
|
sender = "ops@kingsome.cn"
|
|
app = Flask(__name__)
|
|
app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
|
|
app.config['MAIL_PORT'] = '465'
|
|
app.config['MAIL_USE_SSL'] = True
|
|
app.config['MAIL_USE_TLS'] = False ## 默认就是 false, 加上警示自己
|
|
app.config['MAIL_USERNAME'] = sender
|
|
app.config['MAIL_PASSWORD'] = 'bX8cfBAyj9MBqH22'
|
|
mail = Mail(app)
|
|
recipients = ['pengtao@kingsome.cn']
|
|
|
|
|
|
def send_async_email(app, msg):
|
|
with app.app_context():
|
|
mail.send(msg)
|
|
|
|
|
|
@app.route('/')
|
|
def show_index():
|
|
title = "test报表"
|
|
# day = request.args.get('day')
|
|
# project = request.args.get('project') or 'mini_games'
|
|
|
|
|
|
msg = Message(title, sender=sender, recipients=recipients)
|
|
|
|
msg.subject = f"test_游戏日报"
|
|
full_filename = os.path.join(app.config['UPLOAD_FOLDER'], 'img2019-10-31.png')
|
|
msg.html = render_template('index.html', user_image=full_filename)
|
|
|
|
thread = Thread(target=send_async_email, args=[app, msg])
|
|
thread.start()
|
|
|
|
return jsonify("邮件发送成功")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# main()
|
|
app.run(host='0.0.0.0', port=9700, debug=False)
|