邮件问题测试失败

来源:12-7 发送电子邮件 一

慕粉3321357

2018-11-25

这个 授权码 ,有几个, 用哪个呢?
pop3 ,
还是 imap

我这边 好像 有点问题 ,发不了。

from app import mail

from flask_mail import Message


# def send_email(to=None, subject=None, template=None):
def send_email():
    pass
    msg = Message('测试邮件', body='this is test', sender='931367095@qq.com', recipients=['931367095@qq.com'])
    mail.send(message=msg)

感觉报错 不像 flask-mail 的 报错, 官方库 里面的报错

/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/bin/python /Applications/PyCharm.app/Contents/helpers/pydev/pydevd.py --multiproc --qt-support=auto --client 127.0.0.1 --port 55713 --file /Users/frank/PycharmProjects/fisher/fisher.py
pydev debugger: process 21008 is connecting

Connected to pydev debugger (build 182.4505.26)
id:4325603984  app实例化
id:4325603984  app启动
 * Serving Flask app "app" (lazy loading)
 * Environment: production
   WARNING: Do not use the development server in a production environment.
   Use a production WSGI server instead.
 * Debug mode: on
 * Running on http://0.0.0.0:5000/ (Press CTRL+C to quit)
 * Restarting with stat
pydev debugger: process 21009 is connecting

id:4421673648  app实例化
id:4421673648  app启动
 * Debugger is active!
 * Debugger PIN: 185-468-296
127.0.0.1 - - [25/Nov/2018 11:59:28] "GET / HTTP/1.1" 200 -
127.0.0.1 - - [25/Nov/2018 11:59:31] "GET /login HTTP/1.1" 200 -
127.0.0.1 - - [25/Nov/2018 11:59:32] "GET /reset/password HTTP/1.1" 200 -
127.0.0.1 - - [25/Nov/2018 12:00:37] "POST /reset/password HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/frank/PycharmProjects/fisher/app/web/auth.py", line 110, in forget_password_request
    send_email()
  File "/Users/frank/PycharmProjects/fisher/app/libs/email.py", line 18, in send_email
    mail.send(message=msg)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask_mail.py", line 158, in configure_host
    host = smtplib.SMTP(self.mail.server, self.mail.port)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 338, in connect
    (code, msg) = self.getreply()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 394, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed
127.0.0.1 - - [25/Nov/2018 12:01:19] "POST /reset/password HTTP/1.1" 500 -
Traceback (most recent call last):
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/Users/frank/PycharmProjects/fisher/app/web/auth.py", line 110, in forget_password_request
    send_email()
  File "/Users/frank/PycharmProjects/fisher/app/libs/email.py", line 18, in send_email
    mail.send(message=msg)
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/Users/frank/.local/share/virtualenvs/fisher-jkGXuurF/lib/python3.6/site-packages/flask_mail.py", line 158, in configure_host
    host = smtplib.SMTP(self.mail.server, self.mail.port)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 338, in connect
    (code, msg) = self.getreply()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/smtplib.py", line 394, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed

如果 老师有时间,帮忙看下.

写回答

2回答

慕工程0206990

2019-10-18

你好,请问解决了吗,我也遇到了这个问题

0
0

7七月

2018-11-25

这应该是邮件服务器的设置问题,看下官方的文档吧,我也是看腾讯的文档设置的。

0
0

Python Flask高级编程之从0到1开发《鱼书》精品项目

7月老师深入浅出剖析Flask核心机制,和你一起探讨Python高级编程

2735 学习 · 1267 问题

查看课程