Browse Source

Update 'README.md'

天问 1 year ago
parent
commit
eaaaaf52c8
1 changed files with 33 additions and 1 deletions
  1. 33 1
      README.md

+ 33 - 1
README.md

@@ -1,3 +1,35 @@
 # flask_mail
 # flask_mail
 
 
- Flask 的一个邮件扩展
+ 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)
+
+```