Issues sending emails

Hey @JB-Dev sorry about the delayed response, there are two changes to the steps I gave you aboe:

Firstly looks like I forgot to set some more env variables in the commands I gave you which I’ve now added below.
Secondly from testing myself locally you also need to make a direct change to the Baserow config file found in: /baserow/baserow/backend/src/baserow/config/settings/base.py

Could you first edit: /baserow/baserow/backend/src/baserow/config/settings/base.py and find the line EMAIL_BACKEND = "djcelery_email.backends.CeleryEmailBackend" and change it to be EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" . You will probably need to become root to edit this file as I believe the guide has you install baserow using the root user.

This will force Baserow not to use redis and celery to send emails asynchronously, but instead just do it immediately inside the Baserow server, which will let us debug the underlying issue. Once debugged I would recommend reverting the change above.

cd /baserow
source env/bin/activate
export DJANGO_SETTINGS_MODULE='baserow.config.settings.base'
export EMAIL_SMTP='TRUE'
export EMAIL_SMTP_HOST='smtp.gmail.com'
export EMAIL_SMTP_USE_TLS='TRUE'
export EMAIL_SMTP_PORT=587
export EMAIL_SMTP_USER='my@email.com'
export EMAIL_SMTP_PASSWORD='mypassword'
export FROM_EMAIL='my@email.com'
# Missed commands from last time
# These should exactly match what you have set in your `baserow.conf`
export REDIS_HOST='localhost'
export DATABASE_HOST='localhost'
export DATABASE_PASSWORD='REPLACE_WITH_YOUR_DB_PASSWORD'
export MJML_SERVER_HOST='localhost'
baserow shell

Now try copy and pasting the following into the newly opened baserow shell after replacing the REPLACE_WITH_TO_EMAIL_ADDRESS with the email address you want to test sending an email to.

from django.core.mail import EmailMessage
from django.conf import settings

email = EmailMessage(
    'title',
    'msg',
    settings.FROM_EMAIL,
    ['REPLACE_WITH_TO_EMAIL_ADDRESS'],
)
email.send(fail_silently=False)

Hi @nigel,
No problem!
I retried with the extra changes and got this error (Similar to the original it seems):

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/baserow/env/lib/python3.7/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/baserow/env/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/baserow/env/lib/python3.7/site-packages/django/core/mail/backends/smtp.py", line 62, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.7/smtplib.py", line 251, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.7/smtplib.py", line 336, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.7/smtplib.py", line 307, in _get_socket
    self.source_address)
  File "/usr/lib/python3.7/socket.py", line 728, in create_connection
    raise err
  File "/usr/lib/python3.7/socket.py", line 716, in create_connection
    sock.connect(sa)
OSError: [Errno 101] Network is unreachable

Let me know if there’s anything else I need to do!

@JB-Dev

From a quick google of that error it (python - "[Errno 101] Network is unreachable" when trying to send email using Django - Stack Overflow) looks like perhaps the port you are trying to use is being blocked by your hosting provider / firewall setup perhaps?

What happens when you run the following command on your ubuntu server:

telnet smtp.gmail.com 587

Hi @nigel
Thanks for the help!
This turned out to be a very niche issue which may hopefully help someone in the future!
Everything baserow works perfectly, the issue was this:
If you are hosting ANY server on scaleway within their Private networks you need ipv6 enabled on any server you want SMTP to work on.

Ended up not being anything to do with baserow but hopefully someone will find it useful!

Love the product and you were super helpful!

1 Like

Hi!

I just started a container to test Baserow.

Below my docker-compose.yml:

version: "3.4"
services:

  baserow:
    image: baserow/baserow:1.11.0
    container_name: baserow
    hostname: baserow
    volumes:
      - data:/baserow/data
    #ports:
    #  - "80:80"
    #  - "443:443"
    restart: unless-stopped
    environment:
      BASEROW_PUBLIC_URL: 'https://baserow.mydomain.com'
      EMAIL_SMTP: 'TRUE'
      EMAIL_SMTP_HOST: 'mail.mydomain.com'
      EMAIL_SMTP_PORT: 587
      EMAIL_SMTP_USE_TLS: 'TRUE'
      EMAIL_SMTP_USER: 'smtp@mydomain.com'
      EMAIL_SMTP_PASSWORD: 'P@ssw0rd'
      FROM_EMAIL: 'no-reply@mydomain.com'

volumes:
  data:

networks:
  default:
    name: caddy_net
    external: true

After register the first (admin) account I suppose I would receive an email.

But that do not happens.

How do I test/debug this issue?

I can´t use suggested steps above, I think something is different for version 1.11 and/or docker container.

[admin@vps baserow]$ clear ; docker exec -it baserow /bin/bash
root@baserow:/# cd /baserow
root@baserow:/baserow# source env/bin/activate
bash: env/bin/activate: No such file or directory

Hi @peracchi , Sorry for the delay!

Edit: Just to clarify, we don’t send any emails when you first sign up. The only emails we ever send are password reset emails, workspace invite emails and possibly some emails related to account deletion.

I’ve updated my instructions from above to match the new Docker setup. One day I would love to add an email test button somewhere in the settings page!

These instructions are assuming you are using the baserow/baserow:XYZ image (which you are, just for future readers!)

  1. Make sure your Baserow is running as normal (docker-compose up -d etc)
  2. Now open a shell into your Baserow container:
# This will setup the venv, env variables etc for you! 
docker exec -it baserow /baserow.sh backend-cmd bash -c bash
  1. Now change to the backend directory
cd /baserow/backend
  1. Open the Python Shell:
./baserow shell
  1. Now try copy and pasting the following into the newly opened baserow shell after replacing the REPLACE_WITH_TO_EMAIL_ADDRESS with the email address you want to test sending an email to.
from django.core.mail import EmailMessage
from django.conf import settings

email = EmailMessage(
    'title',
    'msg',
    settings.FROM_EMAIL,
    ['REPLACE_WITH_TO_EMAIL_ADDRESS'],
)
email.send(fail_silently=False)

I’ve not personally tested these instructions so perhaps there is a typo, let me know if it doesn’t work!

Thanks @nigel !

I infered this after begin my tests and receive an invite email.

I’m using Baserow behind “my Caddy” because I have more containers and Caddy is really gold as reverse proxy for Docker containers.

Bellow my docker-compose.yml with env variables set (may be useful for someone).

version: "3.4"
services:

  baserow:
    image: baserow/baserow:1.11.0
    container_name: baserow
    hostname: baserow
    volumes:
      - data:/baserow/data
    #ports:
    #  - "80:80"
    #  - "443:443"
    restart: unless-stopped
    environment:
      BASEROW_PUBLIC_URL: 'https://baserow.my.domain'
      EMAIL_SMTP: 'TRUE'
      EMAIL_SMTP_HOST: 'mail.my.domain'
      EMAIL_SMTP_PORT: 587
      EMAIL_SMTP_USE_TLS: 'TRUE'
      EMAIL_SMTP_USER: 'smtp@my.domain'
      EMAIL_SMTP_PASSWORD: 'mY-p@sS0rD'
      FROM_EMAIL: 'Baserow <no-reply@my.domain>'

volumes:
  data:

networks:
  default:
    name: caddy_net
    external: true

Hello @nigel! I’m on a Docker Installation and cannot send emails. I’ve also checked that the username and password work on the SMTP server. I followed your last instructions to try and see any error messages, and I get this when running the Python shell commands:

>>> from django.core.mail import EmailMessage
>>> from django.conf import settings
>>>
>>> email = EmailMessage(
...     'title',
...     'msg',
...     settings.FROM_EMAIL,
...     ['I_REPLACED_THIS_WITH_TO_EMAIL_ADDRESS'],
... )
>>> email.send(fail_silently=False)
[<AsyncResult: 1456cc1f-3f33-49c0-b762-a8ee7822a124>]

I think this means the response is not ready yet, but I don’t know where to go from here to inspect it. It doesn’t print anything else if I wait. Thanks in advance for any advice you can give!

Hey @Beaked do you do these steps also?

Could you first edit: /baserow/baserow/backend/src/baserow/config/settings/base.py and find the line EMAIL_BACKEND = "djcelery_email.backends.CeleryEmailBackend" and change it to be EMAIL_BACKEND = "django.core.mail.backends.smtp.EmailBackend" . You will probably need to become root to edit this file as I believe the guide has you install baserow using the root user.

From the higher post Issues sending emails - #4 by nigel

Without these emails will be sent via an async task which is hard to debug as you can see !

Indeed I had missed that step, thank you! Done it and was able to get an error, but AFAICT it’s the same error that I was seeing in the baserow container logs:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 62, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.9/smtplib.py", line 339, in connect
    self.sock = self._get_socket(host, port, self.timeout)
  File "/usr/lib/python3.9/smtplib.py", line 310, in _get_socket
    return socket.create_connection((host, port), timeout,
  File "/usr/lib/python3.9/socket.py", line 843, in create_connection
    raise err
  File "/usr/lib/python3.9/socket.py", line 831, in create_connection
    sock.connect(sa)
TimeoutError: [Errno 110] Connection timed out

So a timeout but I can’t tell the reason. I’ve made sure that the port, username, password, hostname, and TLS setting that I’m using work (by doing a simple experiment with a Python script). Thanks in advance for any further help you can give.

Hey @Beaked,

That error typically means there is a connection issue between the container and the mail host, As well as Scaleway I have seen other hosts block outbound traffic on 587 to attempt to block spam.

Are you hosting Baserow from “home” or with someone like Hetzner / Digital Ocean?

Hello @joffcom, I’m hosting with ByteHosting. The server is a VPS similar to what you get with Digital Ocean, running Ubuntu. I’ve setup UFW and opened the SMTP port, although as I understand Docker bypasses UFW anyway.

EDIT 1: My SMTP port is not 587, but I’ve set the environment variable EMAIL_SMTP_PORT to the correct one.

EDIT 2: I did a quick test on localhost with the same settings, and it failed differently:

 [CELERY_WORKER][2023-01-23 20:46:49] [2023-01-23 20:44:04,239: INFO/MainProcess] Task djcelery_email_send_multiple[fc9c78f8-558e-4c80-a335-df5b93012454] received
 [CELERY_WORKER][2023-01-23 20:46:49] [2023-01-23 20:46:49,648: ERROR/ForkPoolWorker-1] djcelery_email_send_multiple[fc9c78f8-558e-4c80-a335-df5b93012454]: Cannot reach CELERY_EMAIL_BACKEND django.core.mail.backends.smtp.EmailBackend
 [CELERY_WORKER][2023-01-23 20:46:49] Traceback (most recent call last):
 [CELERY_WORKER][2023-01-23 20:46:49]   File "/baserow/venv/lib/python3.9/site-packages/djcelery_email/tasks.py", line 40, in send_emails
 [CELERY_WORKER][2023-01-23 20:46:49]     conn.open()
 [CELERY_WORKER][2023-01-23 20:46:49]   File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 62, in open
 [CELERY_WORKER][2023-01-23 20:46:49]     self.connection = self.connection_class(self.host, self.port, **connection_params)
 [CELERY_WORKER][2023-01-23 20:46:49]   File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
 [CELERY_WORKER][2023-01-23 20:46:49]     (code, msg) = self.connect(host, port)
 [CELERY_WORKER][2023-01-23 20:46:49]   File "/usr/lib/python3.9/smtplib.py", line 341, in connect
 [CELERY_WORKER][2023-01-23 20:46:49]     (code, msg) = self.getreply()
 [CELERY_WORKER][2023-01-23 20:46:49]   File "/usr/lib/python3.9/smtplib.py", line 398, in getreply
 [CELERY_WORKER][2023-01-23 20:46:49]     raise SMTPServerDisconnected("Connection unexpectedly closed")

This confuses me more, but anyway for now I’ll focus on making localhost work. The error there (in the code above) makes me think maybe TLS mode is not really enabled, although I’m setting it to “True” in the env vars. This is the [redacted] content of the file where I set those:

BASEROW_PUBLIC_URL=http://localhost
FROM_EMAIL="[redacted]@[redacted].[redacted]"
EMAIL_SMTP="True"
EMAIL_SMTP_HOST=[redacted].[redacted].[redacted]
EMAIL_SMTP_PORT=465
EMAIL_SMTP_USER="[redacted]@[redacted].[redacted]"
EMAIL_SMTP_PASSWORD="[redacted]"
EMAIL_SMTP_USE_TLS="True"

I left the actual port FWIW. I’ll also mention that I’ve tried different combinations of quotes and no quotes. As always thanks a lot for all input into this.

EDIT 3: I did the baserow shell test, but again it’s exactly the same error as in the container logs:

[GCC 10.2.1 20210110] on linux
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> from django.core.mail import EmailMessage
>>> from django.conf import settings
>>>
>>> email = EmailMessage(
...     'title',
...     'msg',
...     settings.FROM_EMAIL,
...     ['redacted@redacted.redacted'],
... )
>>> email.send(fail_silently=False)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/message.py", line 284, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 102, in send_messages
    new_conn_created = self.open()
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 62, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.9/smtplib.py", line 341, in connect
    (code, msg) = self.getreply()
  File "/usr/lib/python3.9/smtplib.py", line 398, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed

Hey @Beaked,

Can you set USE_TLS to false, 465 is normally used for SSL rather than TLS / StartTLS so that could be the issue.

I second this… I can’t get this going at all with a gmail account ussing app password credentials… don’t know what else to try…

What settings are you using?

environment:
- BASEROW_PUBLIC_URL=https://mywebsite.com
- BASEROW_CADDY_ADDRESSES=:8080
- EMAIL_SMTP=TRUE
- EMAIL_SMTP_HOST=smtp.gmail.com
- EMAIL_SMTP_PORT=465
- EMAIL_SMTP_USER=mygoogleappuserid@gmail.com
- EMAIL_SMTP_PASSWORD=mygoogleapppass
- EMAIL_SMTP_USE_TLS=FALSE
- FROM_EMAIL=no-reply.tcbaserow@gmail.com

Trying TLS = TRUE and using the TLS port didn’t work for me…

It might be worth making sure the from email matches the user authenticating as that can cause issues with some mail hosts.

It could be worth looking at a service like sendgrid which has a generous free tier, I will do a test with a gmail account over the weekend though to see if it works.

Hey guys,

after reading through the setup docs, the gitlab issues and this thread, along a bunch of other guides and documents, I’ve managed to set up the entire baserow stack based on the no-caddy compose files. Everything apart from the emails works perfectly. The debug and test instructions outlined here don’t seem to apply to me, as I will describe in a second.

The error I get

[2023-03-24 13:19:06,569: WARNING/ForkPoolWorker-2] djcelery_email_send_multiple[1f09f2f6-c9f0-4e63-9f01-ddcd86e1526a]: Failed to send email message to ['inbox@mail.com'], retrying. (SMTPServerDisconnected('Connection unexpectedly closed'))
[2023-03-24 13:19:06,572: INFO/ForkPoolWorker-2] Task djcelery_email_send_multiple[1f09f2f6-c9f0-4e63-9f01-ddcd86e1526a] succeeded in 240.145206590998s: 0
[2023-03-24 13:19:06,573: INFO/MainProcess] Task djcelery_email_send_multiple[1f09f2f6-c9f0-4e63-9f01-ddcd86e1526a] received
[2023-03-24 13:24:07,104: ERROR/ForkPoolWorker-2] djcelery_email_send_multiple[1f09f2f6-c9f0-4e63-9f01-ddcd86e1526a]: Cannot reach CELERY_EMAIL_BACKEND django.core.mail.backends.smtp.EmailBackend
Traceback (most recent call last):
  File "/baserow/venv/lib/python3.9/site-packages/djcelery_email/tasks.py", line 40, in send_emails
    conn.open()
  File "/baserow/venv/lib/python3.9/site-packages/django/core/mail/backends/smtp.py", line 62, in open
    self.connection = self.connection_class(self.host, self.port, **connection_params)
  File "/usr/lib/python3.9/smtplib.py", line 253, in __init__
    (code, msg) = self.connect(host, port)
  File "/usr/lib/python3.9/smtplib.py", line 341, in connect
    (code, msg) = self.getreply()
  File "/usr/lib/python3.9/smtplib.py", line 398, in getreply
    raise SMTPServerDisconnected("Connection unexpectedly closed")
smtplib.SMTPServerDisconnected: Connection unexpectedly closed

environment variables from compose.yml

  # Set these to enable Baserow to send emails.
  EMAIL_SMTP: "true" #putting true without quotes makes no difference
  EMAIL_SMTP_HOST: "server.mail.com"
  EMAIL_SMTP_PORT: 465
  EMAIL_SMTP_USE_TLS: #setting or not setting this makes no difference
  EMAIL_SMTP_USER: "vps"
  EMAIL_SMTP_PASSWORD: "password"
  FROM_EMAIL: "baserow@mail.com"

I’m running a bunch of other services from this server, which all use the same mailserver, credentials and port. Therefore im certain that these are correct.
Since I’m using the no-caddy compose file (/baserow/-/blob/develop/docker-compose.no-caddy.yml), it is too long to post here. I will supply needed sections from it when asked for.

Regarding the debug steps described in this post

  • The instructions from post #9 don’t seem to be applicable in my case. The baserow.sh file exists nowhere in the baserow-backend container. Running ./baserow shell from the backend directory, as instructed, returns /usr/bin/env: 'python': No such file or directory.
  • The instructions from post #4 also don’t seem to apply, because the error already states that the django.core.mail yada yada backend is being used. I did not try to change the backend to the CeleryMailBackend, mainly because I am not too sure how to in my case.

An issue on gitlab talking about SSL ports (/baserow/-/issues/1646) also has caught my attention. Since I’m forced to use port 465, I really hope there is no arbitrary limit which mail ports are usable.

I’d love to get some advice what to do here. I’m so close to deploying Baserow and wouldn’t wanna be stopped by emails not working! Thanks in advance.

It’s been a couple days, so to break the silence I’ll ping the two prominent helpers in this thread - @joffcom or @nigel, do any of you have an idea how to probe or solve this issue further?

Thanks in advance.

Hi @angelfish i wonder if this issue is the problem you are hitting No overriding django default EMAIL_USE_SSL in base.py (#1646) · Issues · Baserow / baserow · GitLab

Edit: you’ve already pointed this out above my bad!