以下を実行すると、自分の gmail アカウントから自分の gmail アカウントに電子メールを送信することが期待されます。代わりに、タイムアウト エラーが発生します。ここにあるものを含め、考えられるすべての可能な組み合わせを試してみました
import os
from flask import Flask
from flask.ext.mail import Mail, Message
app =Flask(__name__)
mail=Mail(app)
USERNAME = 'my_gmail_username@gmail.com'
PASSWORD = 'my_gmail_password@gmail.com'
app.config.update(
MAIL_SERVER = 'smtp.gmail.com',
MAIL_PORT = 465,
MAIL_USE_SSL = True,
# MAIL_USE_TSL = True,
MAIL_USERNAME = USERNAME,
MAIL_PASSWORD = PASSWORD,
MAIL_FAIL_SILENTLY=False,
DEBUG = True)
mail=Mail(app)
@app.route("/")
def index():
msg = Message("Hello",
sender=USERNAME,
recipients=[USERNAME])
msg.body = "This is the email body"
mail.send(msg)
return "Sent"
if __name__ == "__main__":
app.run()
私は得る:
* Running on http://127.0.0.1:5000/
* Restarting with reloader
127.0.0.1 - - [03/Aug/2013 04:03:49] "GET / HTTP/1.1" 500 -
Traceback (most recent call last):
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
return self.wsgi_app(environ, start_response)
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
response = self.make_response(self.handle_exception(e))
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
reraise(exc_type, exc_value, tb)
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
response = self.full_dispatch_request()
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
rv = self.handle_user_exception(e)
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
reraise(exc_type, exc_value, tb)
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
rv = self.dispatch_request()
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
return self.view_functions[rule.endpoint](**req.view_args)
File "/home/drew/mail/postoffice.py", line 35, in index
mail.send(msg)
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask_mail.py", line 415, in send
with self.connect() as connection:
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask_mail.py", line 123, in __enter__
self.host = self.configure_host()
File "/home/drew/.virtualenvs/mail2/lib/python2.7/site-packages/flask_mail.py", line 135, in configure_host
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
File "/usr/lib/python2.7/smtplib.py", line 776, in __init__
SMTP.__init__(self, host, port, local_hostname, timeout)
File "/usr/lib/python2.7/smtplib.py", line 265, in __init__
addr = socket.gethostbyname(socket.gethostname())
error: [Errno 110] Connection timed out
127.0.0.1 - - [03/Aug/2013 04:03:49] "GET /?__debugger__=yes&cmd=resource&f=style.css HTTP/1.1" 200 -
127.0.0.1 - - [03/Aug/2013 04:03:49] "GET /?__debugger__=yes&cmd=resource&f=jquery.js HTTP/1.1" 200 -
127.0.0.1 - - [03/Aug/2013 04:03:49] "GET /?__debugger__=yes&cmd=resource&f=debugger.js HTTP/1.1" 200 -
127.0.0.1 - - [03/Aug/2013 04:03:49] "GET /?__debugger__=yes&cmd=resource&f=console.png HTTP/1.1" 200 -
127.0.0.1 - - [03/Aug/2013 04:03:49] "GET /?__debugger__=yes&cmd=resource&f=source.png HTTP/1.1" 200