Created
August 4, 2015 07:48
-
-
Save binderclip/d3ea0f7fc7a91ac8f72e to your computer and use it in GitHub Desktop.
用 Flask-Mail 通过 QQ 邮箱发送邮件
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask | |
from flask_mail import Mail, Message | |
app = Flask(__name__) | |
app.config.update( | |
#EMAIL SETTINGS | |
MAIL_SERVER='smtp.qq.com', | |
MAIL_PORT=465, | |
MAIL_USE_SSL=True, | |
MAIL_USERNAME = 'QQIDHere', | |
MAIL_PASSWORD = 'QQPasswordHere' | |
) | |
mail = Mail(app) | |
@app.route("/") | |
def index(): | |
msg = Message(subject="Hello", | |
sender='[email protected]', | |
recipients=['recipient@recipient_domain.com']) | |
msg.html = "<b>testing</b> html" | |
mail.send(msg) | |
return '<h1>Sent</h1>' | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
用 Flask-Mail 模块来发送邮件。
如果没有试过用 Python 发邮件的话建议顺便看一下我的另外一个 Gist 用 Python 发送 QQ 邮箱的邮件。
下面是这个 Gist 的参考: