是否可以使用flask-mail从localhost发送电子邮件?

时间:2015-03-20 19:12:29

标签: python flask smtp smtplib flask-mail

我正在使用Windows操作系统并尝试使用flask-email扩展程序从localhost发送电子邮件。我的代码如下:

#!/usr/bin/env python
# -*- coding: UTF-8 -*-

from flask import Flask
from flask.ext.mail import Mail, Message

app = Flask(__name__)
mail = Mail(app)

app.config['MAIL_SERVER'] = 'smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USE_TLS'] = True
app.config['MAIL_USE_SSL'] = False
app.config['MAIL_USERNAME'] = "example@gmail.com"
app.config['MAIL_PASSWORD'] = "783798kljkld"


@app.route("/")
def index():
    msg = Message("Hello", sender="example@gmail.com", recipients=["to@gmail.com"])
    msg.body = "testing"
    msg.html = "<b>testing</b>"
    return mail.send(msg)


if __name__ == '__main__':
    app.run(debug=True)

当我在调试模式下运行此代码时,浏览器会给出响应&#34; SMTPServerDisconnected:Connection意外关闭&#34;

那么,我的代码和问题中的问题是什么?如何使用localhost中的flask-email扩展名发送电子邮件?

0 个答案:

没有答案