使用Python Falsk-Mail 发送邮件
安装扩展
pip3 install flask-mail
详细代码
from flask_mail import Mail,Message from flask import Flask app = Flask(__name__) app.config.update( MAIL_SERVER = 'smtp.163.com', MAIL_PORT = 25, MAIL_USE_TLS = True, MAIL_USERNAME = 'XXXX@163.com', MAIL_PASSWORD = 'XXXXXX', MAIL_DEFAULT_SENDER = 'XXXX@163.com', ) @app.route('/') def sendmail(): mail = Mail(app) message = Message(subject='first mail', recipients=['XXXXXX@qq.com'], body="This is a test mail!") mail.send(message) return "发送成功!" if __name__ == '__main__': app.run()
效果图