2022丝路通:发送邮件接口

来自CloudWiki
跳转至: 导航搜索

代码

from flask import Flask
from flask_mail import Mail, Message

app = Flask(__name__)

app.config['MAIL_SERVER'] = 'smtp.qq.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'maxin5452@qq.com'
app.config['MAIL_PASSWORD'] = '****************' #这里替换成你的邮箱授权码
app.config['MAIL_USE_SSL'] = True

mail = Mail(app)

@app.route("/")
def index():
    msg = Message('Hello', sender='maxin5452@qq.com', recipients=['458976849@qq.com'])
    msg.body = "This is the email body"
    mail.send(msg)
    return "Sent"

if __name__ == '__main__':
    app.run(host="0.0.0.0",debug=True,port='5002')

验证

浏览器访问http://119.3.212.161:5002/ 即可发送成功。