Flask 的一个邮件扩展 https://github.com/mattupstate/flask-mail
天问 eaaaaf52c8 Update 'README.md' | 8 months ago | |
---|---|---|
README.md | 8 months ago |
Flask 的一个邮件扩展
## Usage
from flask import Flask
from flask_mail import Mail, Message
app = Flask(__name__)
app.config['MAIL_SERVER'] = 'smtp.example.com'
app.config['MAIL_PORT'] = 587
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USERNAME'] = 'your_email@example.com'
app.config['MAIL_PASSWORD'] = 'your_email_password'
mail = Mail(app)
@app.route('/')
def index():
# 创建邮件消息对象
msg = Message('Hello from Flask-Mail',
sender='your_email@example.com',
recipients=['recipient@example.com'])
# 设置邮件内容
msg.body = "This is a test email sent from Flask-Mail!"
# 发送邮件
mail.send(msg)
return 'Email sent successfully!'
if __name__ == '__main__':
app.run(debug=True)