emailhelper-api-v0.1/app.py

41 lines
1.0 KiB
Python

from flask import Flask, request, render_template
from flask_mail import Mail, Message
from threading import Thread
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.exmail.qq.com'
app.config['MAIL_PORT'] = 25
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'fecribd@fecr.com.cn'
app.config['MAIL_PASSWORD'] = 'BUSUieYfdy8u7ngX'
mail = Mail(app)
def send_async_email(mail_app, msg):
with mail_app.app_context():
mail.send(msg)
@app.route('/send_mail', methods=['POST'])
def send_mail():
title = request.json['title']
sender = request.json['sender']
recipients = request.json['recipients']
msg_body = request.json['msg_body']
msg = Message(title, sender=sender, recipients=recipients)
msg.body = msg_body
# msg.html = render_template('email.html', user=msg_body['user'], verify_code=msg_body['verify_code'])
thread = Thread(target=send_async_email, args=[app, msg])
thread.start()
return "邮件已发送"
if __name__ == '__main__':
app.run()