briancappello / flask-react-spa

A production-ready boilerplate built with Python 3, Flask and ES6 React/Redux
MIT License
548 stars 110 forks source link

Anyone using this with gmail? #15

Open chppppp opened 5 years ago

chppppp commented 5 years ago

here is my mail config

    MAIL_ADMINS = ('myaddr@gmail.com',)  # FIXME
    MAIL_SERVER = os.environ.get('FLASK_MAIL_HOST', 'smtp.gmail.com')
    MAIL_PORT = int(os.environ.get('FLASK_MAIL_PORT', 587))    # tls
    #MAIL_PORT = int(os.environ.get('FLASK_MAIL_PORT', 465))     # ssl
    MAIL_USE_TLS = get_boolean_env('FLASK_MAIL_USE_TLS', True)
    MAIL_USE_SSL = get_boolean_env('FLASK_MAIL_USE_SSL', False)
    MAIL_USERNAME = os.environ.get('FLASK_MAIL_USERNAME', 'myaddr@gmail.com')
    MAIL_PASSWORD = os.environ.get('FLASK_MAIL_PASSWORD', 'myapppass')
    MAIL_DEFAULT_SENDER = (
        os.environ.get('FLASK_MAIL_DEFAULT_SENDER_NAME', 'Flask React SPA'),
        os.environ.get('FLASK_MAIL_DEFAULT_SENDER_EMAIL',
                       f"noreply@{os.environ.get('FLASK_DOMAIN', 'localhost')}")
    )

I get an error Network Unreachable


[2019-11-12 17:30:57,990: INFO/MainProcess] Received task: backend.tasks.send_mail_async_task[ed6f60b9-4f23-45ec-b954-e5c5e76c1373]
[2019-11-12 17:30:57,991: DEBUG/MainProcess] TaskPool: Apply <function _fast_trace_task at 0x7f8b56b2bd08> (args:('backend.tasks.send_mail_async_task', 'ed6f60b9-4f23-45ec-b954-e5c5e76c1373', {'lang': 'py', 'task': 'backend.tasks.send_mail_async_task', 'id': 'ed6f60b9-4f23-45ec-b954-e5c5e76c1373', 'shadow': None, 'eta': None, 'expires': None, 'group': None, 'retries': 0, 'timelimit': [None, None], 'root_id': 'ed6f60b9-4f23-45ec-b954-e5c5e76c1373', 'parent_id': None, 'argsrepr': '(<flask_mail.Message object at 0x7f9ba724d5c0>,)', 'kwargsrepr': '{}', 'origin': 'gen13146@frickyou', 'reply_to': '7e5f5826-1177-36ef-8d89-feebe795adad', 'correlation_id': 'ed6f60b9-4f23-45ec-b954-e5c5e76c1373', 'delivery_info': {'exchange': '', 'routing_key': 'celery', 'priority': 0, 'redelivered': None}}, b'\x80\x02cflask_mail\nMessage\nq\x00)\x81q\x01}q\x02(X\n\x00\x00\x00recipientsq\x03]q\x04X\x1a\x00\x00\x00myaddr+ccc@gmail.comq\x05aX\x07\x00\x00\x00subjectq\x06X\x07\x00\x00\x00Welcomeq\x07X\x06\x00\x00\x00senderq\x08X\x0f\x00\x00\x00Flask React... kwargs:{})
[2019-11-12 17:30:57,993: DEBUG/MainProcess] Task accepted: backend.tasks.send_mail_async_task[ed6f60b9-4f23-45ec-b954-e5c5e76c1373] pid:10190
[2019-11-12 17:33:09,138: ERROR/ForkPoolWorker-4] Task backend.tasks.send_mail_async_task[ed6f60b9-4f23-45ec-b954-e5c5e76c1373] raised unexpected: OSError(101, 'Network is unreachable')
Traceback (most recent call last):
  File "/home/lou/lou/flask-react-spa/FRSpa/lib/python3.6/site-packages/celery/app/trace.py", line 382, in trace_task
    R = retval = fun(*args, **kwargs)
  File "/home/lou/lou/flask-react-spa/backend/extensions/celery.py", line 25, in __call__
    return BaseTask.__call__(self, *args, **kwargs)
  File "/home/lou/lou/flask-react-spa/FRSpa/lib/python3.6/site-packages/celery/app/trace.py", line 641, in __protected_call__
    return self.run(*args, **kwargs)
  File "/home/lou/lou/flask-react-spa/backend/tasks.py", line 17, in send_mail_async_task
    mail.send(msg)
  File "/home/lou/lou/flask-react-spa/FRSpa/lib/python3.6/site-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/home/lou/lou/flask-react-spa/FRSpa/lib/python3.6/site-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/home/lou/lou/flask-react-spa/FRSpa/lib/python3.6/site-packages/flask_mail.py", line 156, in configure_host
    host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
  File "/usr/lib/python3.6/smtplib.py", line 1031, in __init__
    source_address)
  File "/usr/lib/python3.6/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.6/smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.6/smtplib.py", line 1037, in _get_socket
    self.source_address)
  File "/usr/lib/python3.6/socket.py", line 724, in create_connection
    raise err
  File "/usr/lib/python3.6/socket.py", line 713, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

I tested connectivity and I can open the socket remotely

(FRSpa) lou@frickyou:~/lou/flask-react-spa$ telnet smtp.gmail.com 465
Trying 173.194.175.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
^CConnection closed by foreign host.
(FRSpa) lou@frickyou:~/lou/flask-react-spa$
(FRSpa) lou@frickyou:~/lou/flask-react-spa$ telnet smtp.gmail.com 587
Trying 173.194.175.109...
Connected to smtp.gmail.com.
Escape character is '^]'.
220 smtp.gmail.com ESMTP t65sm16314qkh.99 - gsmtp
^C^]
telnet> quit
Connection closed.

Am I missing a config item somewhere?

Thanks!

briancappello commented 5 years ago

GMail is pretty tricky, if I remember correctly. It's been a long time :) Try searching for "flask-mail gmail" or something similar.

Eg this answer looks promising: https://stackoverflow.com/questions/37058567/configure-flask-mail-to-use-gmail

chppppp commented 5 years ago

Thanks @briancappello !!! I am decent at python, pretty newbish to the details on Flask and know enough React to be (barely) dangerous. I very much appreciate you replying to my issue and I will try not to inundate you with newb issues <3

I will leave this issue open until I find a solution and will close when I figure it out.

Thanks!!!

Mtemi commented 4 years ago

gmail appeared tricky, am getting error on, "connection was reset by peer" , could there be a background process resetting the gmail connections?

Sarojkumar1212 commented 4 years ago

Thanks @briancappello !!! I am decent at python, pretty newbish to the details on Flask and know enough React to be (barely) dangerous. I very much appreciate you replying to my issue and I will try not to inundate you with newb issues <3

I will leave this issue open until I find a solution and will close when I figure it out.

Thanks!!!

Hello, I am not sure if you have got it resolved already. It worked for me. The configuration you have done as above is absolutely correct. But additionally, you have to comment/delete another row in the config file where MAIL_PORT is overwritten to 1025. Then it works.

Thanks !!!