Mail setup in docker-compose version raises ERROR

#1

I created a new account from mailgun and use it for Redash, but failed as below when I ran “docker-compose run --rm server manage send_test_mail”. Anyone running into the similar issue? Thanks for advice in advance.

docker-compose run --rm server manage send_test_mail
Starting redash_postgres_1 … done
Starting redash_redis_1 … done
[2018-11-18 18:04:37,740][PID:1][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2018-11-18 18:04:37,758][PID:1][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
Traceback (most recent call last):
File “/app/manage.py”, line 9, in
manager()
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 716, in call
return self.main(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/flask/cli.py”, line 345, in main
return AppGroup.main(self, *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 696, in main
rv = self.invoke(ctx)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 1060, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 889, in invoke
return ctx.invoke(self.callback, **ctx.params)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/decorators.py”, line 17, in new_func
return f(get_current_context(), *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/flask/cli.py”, line 229, in decorator
return __ctx.invoke(f, *args, **kwargs)
File “/usr/local/lib/python2.7/dist-packages/click/core.py”, line 534, in invoke
return callback(*args, **kwargs)
File “/app/redash/cli/init.py”, line 70, in send_test_mail
body=“Test message.”))
File “/usr/local/lib/python2.7/dist-packages/flask_mail.py”, line 491, in send
with self.connect() as connection:
File “/usr/local/lib/python2.7/dist-packages/flask_mail.py”, line 144, in enter
self.host = self.configure_host()
File “/usr/local/lib/python2.7/dist-packages/flask_mail.py”, line 156, in configure_host
host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
File “/usr/lib/python2.7/smtplib.py”, line 801, in init
SMTP.init(self, host, port, local_hostname, timeout)
File “/usr/lib/python2.7/smtplib.py”, line 256, in init
(code, msg) = self.connect(host, port)
File “/usr/lib/python2.7/smtplib.py”, line 316, in connect
self.sock = self._get_socket(host, port, self.timeout)
File “/usr/lib/python2.7/smtplib.py”, line 806, in _get_socket
new_socket = socket.create_connection((host, port), timeout)
File “/usr/lib/python2.7/socket.py”, line 557, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

**here is part of env for SMTP
REDASH_HOST=“172.22.9.2XX”
REDASH_MAIL_SERVER=“smtp.mailgun.org
REDASH_MAIL_PORT=587
REDASH_MAIL_USE_TLS=“true”
REDASH_MAIL_USE_SSL=“false”
REDASH_MAIL_USERNAME="postmaster@XXXXX.mailgun.org"
REDASH_MAIL_PASSWORD=“d7fdf8ffcc3c65bee3ceca3fb1de30ba-XXXXXXX”
REDASH_MAIL_DEFAULT_SENDER="postmaster@XXXXX.mailgun.org"

0 Likes

#2

Looks like some DNS issue. Are you sure your container can access external networks?

0 Likes

#3

Thanks for advice. inside container fo redash_server_1, I was successfully able to send out an email via mailgun using cURL. Any other idea? Can you take a look at my env file to see if there is any incorrect config? Thanks.

0 Likes

#4

Using curl and their http API?

0 Likes

#5

I tried sending an email on the host running docker containers using both API and python send_email script. Both succeeded, but stil failed with “”.

Here is Python script I ran on the host. FYI, sone private info is masked on purpose.

import smtplib
def send_email(mail_user, mail_password, mail_recipient, subject, body):
FROM = mail_user
TO = mail_recipient if type(mail_recipient) is list else [mail_recipient]
SUBJECT = subject
TEXT = body

# Prepare actual message
message = """From: %s\nTo: %s\nSubject: %s\n\n%s
""" % (FROM, ", ".join(TO), SUBJECT, TEXT)
try:
    # server = smtplib.SMTP_SSL("smtp.mailgun.org", 465)
    # server.ehlo()

    server = smtplib.SMTP("smtp.mailgun.org", 587)
    server.ehlo()
    server.starttls()
    server.login(mail_user, mail_password)
    server.sendmail(FROM, TO, message)
    server.close()
    return 'successfully sent the mail'
except Exception as e:
    print(e)
    return "failed to send mail"

if name == “main”:
print(“hello”)
print(send_email(‘no-reply@k8XX.k1ong.com’,‘XXXX’,‘junXXXXX@gmail.com’,‘test in XXX’,‘hi Jun,’))

Here is the config of env

PYTHONUNBUFFERED=0
REDASH_LOG_LEVEL=INFO
REDASH_REDIS_URL=redis://redis:6379/0
POSTGRES_PASSWORD=kdZ5lV7xTo7ulPfXXXXX
REDASH_COOKIE_SECRET=iQgLv0vCNhmPxvWzdSXXXXX
REDASH_DATABASE_URL=postgresql://postgres:kdZ5lV7xTo7ulPXXXX@postgres/postgres
REDASH_HOST=“sXe-.XXXX.com”

REDASH_MAIL_SERVER=“smtp.mailgun.org
REDASH_MAIL_PORT=587
REDASH_MAIL_USE_TLS=“true”
REDASH_MAIL_USE_SSL=“false”
REDASH_MAIL_USERNAME="no-reply@k8XX.k1ong.com"
REDASH_MAIL_PASSWORD=“XXXX”
REDASH_MAIL_DEFAULT_SENDER="no-reply@k8XX.k1ong.com"

Any comment would be appreciated.

0 Likes

#6

another is info .

REDASH_HOST would be resolved to private IP. Should I specify shared public IO explicitly if it causes any issue?

0 Likes

#7

Did you try running same script in the Docker container?

The Docker container runs with different network configuration, so the fact it works on the host doesn’t mean it will work in the container.

0 Likes

#8

I’m having this exact issue. I’m running a VM in Google Compute Engine. Used the setup guide to import the official image. Here’s the command I ran and its output:

root@redashserver:/opt/redash# docker-compose run --rm server manage send_test_mail
Starting redash_redis_1    ... done
Starting redash_postgres_1 ... done
[2019-01-18 22:43:54,920][PID:1][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/Grammar.txt
[2019-01-18 22:43:54,950][PID:1][INFO][root] Generating grammar tables from /usr/lib/python2.7/lib2to3/PatternGrammar.txt
Traceback (most recent call last):
  File "/app/manage.py", line 9, in <module>
    manager()
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 716, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 345, in main
    return AppGroup.main(self, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 696, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 1060, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 889, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/decorators.py", line 17, in new_func
    return f(get_current_context(), *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/flask/cli.py", line 229, in decorator
    return __ctx.invoke(f, *args, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/click/core.py", line 534, in invoke
    return callback(*args, **kwargs)
  File "/app/redash/cli/__init__.py", line 68, in send_test_mail
    body="Test message."))
  File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 491, in send
    with self.connect() as connection:
  File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 144, in __enter__
    self.host = self.configure_host()
  File "/usr/local/lib/python2.7/dist-packages/flask_mail.py", line 156, in configure_host
    host = smtplib.SMTP_SSL(self.mail.server, self.mail.port)
  File "/usr/lib/python2.7/smtplib.py", line 801, in __init__
    SMTP.__init__(self, host, port, local_hostname, timeout)
  File "/usr/lib/python2.7/smtplib.py", line 256, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python2.7/smtplib.py", line 316, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python2.7/smtplib.py", line 806, in _get_socket
    new_socket = socket.create_connection((host, port), timeout)
  File "/usr/lib/python2.7/socket.py", line 557, in create_connection
    for res in getaddrinfo(host, port, 0, SOCK_STREAM):
socket.gaierror: [Errno -2] Name or service not known

And here’s what my env settings look like:

I see the note about trying the script with the docker. Not sure exactly how that would be different or how I’d do that exactly. I’m guessing this might have something to do with firewall settings, but I don’t really know for sure on that.

Any ideas on how to resolve this error would be appreciated.

0 Likes

#9

sorry. I am still facing the same issue.

0 Likes

#10

I gotta figure this out because I would really like to get mailgun to work. It’s almost certainly a DNS issue, but since there’s no documentation on how the DNS is setup in the container it’s hard for me to troubleshoot. And I’ve had trouble getting the containers to actually startup if I try to do any modifcations with docker run.

0 Likes

#11

Removing all double quotes in the env setting file works for me somehow

0 Likes