Flask电子邮件支持 - 发送电子邮件时获取SSLError [Errno 1] [英] Flask Email Support - Get SSLError [Errno 1] when sending email

查看:676
本文介绍了Flask电子邮件支持 - 发送电子邮件时获取SSLError [Errno 1]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为Flask应用程序设置一个电子邮件服务器。我得到一个SSLError这是我第一次学习任何类型的网页开发。

I'm trying to set up an email server for a Flask app. I'm getting an SSLError. This is my first time learning any sort of web development.

以下是我如何配置服务器:

Here is how I've configured the server:

# mail server settings
MAIL_SERVER = 'smtp.mail.yahoo.com'
MAIL_PORT = 587
MAIL_USE_TLS = False
MAIL_USE_SSL = True
MAIL_USERNAME = 'email@yahoo.com'
MAIL_PASSWORD = 'password'


# administrator list
ADMINS = ['email@yahoo.com']

这里是我的 init 脚本处理邮件的一部分:

And here is the part of my init script that deals with mail:

app.config.from_object('config')
mail = Mail(app)

当我尝试发送电子邮件时,这是错误的回溯:

Here is the traceback of the error when I try to send an email:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/Users/user/microblog/flask/lib/python2.7/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/Users/user/microblog/flask/lib/python2.7/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/Users/user/microblog/flask/lib/python2.7/site-packages/flask_mail.py", line 156, in configure_host
    host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 777, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 250, in __init__
    (code, msg) = self.connect(host, port)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 310, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/smtplib.py", line 783, in _get_socket
    new_socket = ssl.wrap_socket(new_socket, self.keyfile, self.certfile)
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 387, in wrap_socket
    ciphers=ciphers)    
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 143, in __init__
    self.do_handshake()    
  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/ssl.py", line 305, in do_handshake
    self._sslobj.do_handshake()   
ssl.SSLError: [Errno 1] _ssl.c:504: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

谢谢!

推荐答案

MAIL_PORT = 587
MAIL_USE_TLS = False
MAIL_USE_SSL = True

端口587用于exp合法的TLS(STARTTLS命令),所以你可能必须使用MAIL_USE_TLS而不是MAIL_USE_SSL。 MAIL_USE_SSL用于隐式TLS,您可以直接使用端口465上的TLS连接。

Port 587 is for explicit TLS (STARTTLS command) so you probably have to use MAIL_USE_TLS and not MAIL_USE_SSL. MAIL_USE_SSL is for implicit TLS where you directly connect with TLS on port 465.

这篇关于Flask电子邮件支持 - 发送电子邮件时获取SSLError [Errno 1]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆