I have a weird issue with no ideas what could be wrong, so maybe writing it here can help me come up with ideas. Or someone can help me :)
I have a Django site running in rancher and for past few weeks I noticed emails are not working. Timeout error is raised. I am using mailgun.org as SMTP server.
This is output from rancher container console:
/app/app # ipython
Python 2.7.14 (default, Dec 19 2017, 22:36:09)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from smtplib import SMTP
In [2]: smtp = SMTP(host='smtp.mailgun.org', port=587)
And it just hangs. Adding timeout raises timeout of course.
I would guess there is something wrong with mailgun. But running same code on same image locally works (commit-hash
matches the one on rancher container).
docker run -ti registry.gitlab.com/namespace/app:commit-hash /bin/sh
/app/app # ipython
Python 2.7.14 (default, Dec 19 2017, 22:36:09)
Type "copyright", "credits" or "license" for more information.
IPython 5.5.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: from smtplib import SMTP
In [2]: smtp = SMTP(host='smtp.mailgun.org', port=587)
In [3]:
I do not get how it works. I contacted mailgun support with a question if they block my server's ip address. Their answer:
We are not blocking the production IP. The only way one environment can work and not another is that there is some aspect of your two environments that is different, so we would recommend reviewing the configurations on your side.
What can be different there if I am using same docker image? Only way I alter environment are env variables, but none of them are related to python/system.
I thought error was cased by me using gevent, but I removed it yesterday.
Please try "telnet smtp.mailgun.org 587" in docker console
/app/app # telnet smtp.mailgun.org 587
telnet: can't connect to remote host (52.10.40.100): Operation timed out
/app/app #
first lines of Dockerfile:
FROM python:2.7-alpine
ENV PYTHONUNBUFFERED 1
# Install dependencies
RUN apk update && \
apk add --no-cache build-base \
curl \
nano \
postgresql-dev \
vim
telnet from host machine:
~# telnet smtp.mailgun.org 587
Trying 34.232.180.42...
Trying 54.164.235.211...
Trying 34.237.7.101...
telnet: Unable to connect to remote host: Connection timed out
Hello,
In order to respond favorably to your request to unblock port 25 of your server, an additional verification is necessary. ...
Looks like provider (Scaleway.com) blocked that port.
I had no idea hosting companies are doing this, when I was using external service for email. Anyway, verified my account, disabled blocking, hard-rebooted server and it works.
Thanks you all for comments/help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With