使用nginx uwsgi时,Flask-Mail发送SMTP电子邮件失败,连接被拒绝错误

时间:2016-10-11 14:54:30

标签: python nginx flask flask-mail

我正在尝试使用Flask-Mail从我的应用程序发送电子邮件。当我从开发服务器运行它时,我的代码工作正常但是当我使用uwsgi和nginx部署它时,我不再能发送电子邮件了。提供了错误回溯。我该如何解决这个问题?

Traceback (most recent call last):
  File "./resources/forget_password.py", line 41, in post
    mail.send(msg)
  File "/home/www/shopolot/env/local/lib/python2.7/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/home/www/shopolot/env/local/lib/python2.7/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/home/www/shopolot/env/local/lib/python2.7/site-packages/flask_mail.py", line 158, in configure_host
    host = smtplib.SMTP(self.mail.server, self.mail.port)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 291, in _get_socket
    return socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 571, in create_connection
    raise err
error: [Errno 111] Connection refused

1 个答案:

答案 0 :(得分:2)

我遇到了同样的麻烦,直到在我的wsgi配置文件中添加“threads = 2”。 而且,差点忘了,我使用Threads进行邮寄。