gpt4 book ai didi

flask - 使用 Flask-Mail 发送邮件时连接被拒绝

转载 作者:行者123 更新时间:2023-12-03 15:33:43 25 4
gpt4 key购买 nike

我在使用 Flask-mail ( http://pythonhosted.org/flask-mail/ ) 发送电子邮件时遇到问题

from flask.ext.sqlalchemy import SQLAlchemy
from flask import Flask, request, session, g, redirect, url_for, abort, render_template, flash
from flask.ext.mail import Mail, Message
import os

# configuration
DEBUG = True
SECRET_KEY = 'hidden'
USERNAME = 'secret'
PASSWORD = 'secret'

MAIL_SERVER='smtp.gmail.com'
MAIL_PORT=587
MAIL_USE_TLS = False
MAIL_USE_SSL= True
MAIL_USERNAME = 'user@gmail.com'
MAIL_PASSWORD = 'password'

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

@app.route('/minfo')
def send_mail():
msg = Message(
'Hello',
sender='user@gmail.com',
recipients=
['user@gmail.com.com'])
msg.body = "This is the email body"
mail.send(msg)
return "Sent"

当我去/minfo 我得到
12:25:57 web.1  |     return socket.create_connection((port, host), timeout)
12:25:57 web.1 | File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 571, in create_connection
12:25:57 web.1 | raise err
12:25:57 web.1 | error: [Errno 61] Connection refused

我不知道是什么坏了或如何修复它,已经在谷歌上搜索了几个小时。有人经历过吗?

最佳答案

  • 您必须设置 flask 配置:
    app = Flask(__name__)
    app.config.from_object(__name__)
    mail = Mail(app)
  • 使用 465 端口。
  • 关于flask - 使用 Flask-Mail 发送邮件时连接被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17404854/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com