docker icon indicating copy to clipboard operation
docker copied to clipboard

Setting up email

Open rolandgeider opened this issue 3 years ago • 9 comments

It seems the FROM_EMAIL is getting lost somewhere:

Discussed in https://github.com/wger-project/docker/discussions/33

Originally posted by TryCatchCrash October 23, 2022 I've set up prod.env for email (i know the settings are fine since i have a non-docker instance running and sending mails with the same settings) and it seems to ignore the FROM_EMAIL setting.

I see in the wger_server log: smtplib.SMTPDataError: (553, b'Relaying disallowed as [email protected]')

FROM_EMAIL is set to admin@<mydomain.ext>

Am I doing something wrong or is this a bug?

rolandgeider avatar Oct 25 '22 12:10 rolandgeider

does the error still occur @TryCatchCrash ? I had no problems sending mails with this config (both over the UI such as "forgot password" as within the container with "python3 manage.py sendtestemail [email protected]"

ENABLE_EMAIL=True
EMAIL_HOST=server.com
EMAIL_PORT=587
[email protected]
EMAIL_HOST_PASSWORD=1234
EMAIL_USE_TLS=True
EMAIL_USE_SSL=False

[email protected]
[email protected]

rolandgeider avatar Dec 15 '22 14:12 rolandgeider

@rolandgeider I've just pulled fresh images and started up and I'm getting: CSRF verification failed. Request aborted.

When i checked the logs i see (domain redacted, but same in both logs) Set site URL to https://mydomain.xyz and Forbidden (Origin checking failed - https://mydomain.xyz does not match any trusted origins.): /en/user/login

It's the same prod.env as before that worked. I'll try fixing that when i get some time and get back to you.

TryCatchCrash avatar Dec 15 '22 18:12 TryCatchCrash

Oh yes, looks like you runned into https://github.com/wger-project/wger/issues/1203

Django 4 is a bit stricter with the CSRF security checkings so we must currently set the trusted domains manually. I hope we can find an easier solution in the future by setting some headers (https://github.com/wger-project/wger/issues/1206)

rolandgeider avatar Dec 15 '22 18:12 rolandgeider

Added CSRF_TRUSTED_ORIGINS to prod.env and now i can login.

Tried to send verification e-mail from preferences.

prod.env: # The 'from' address used when sending emails FROM_EMAIL=admin@<redacted>.xyz # https://docs.djangoproject.com/en/4.1/topics/email/#smtp-backend ENABLE_EMAIL=True EMAIL_HOST=smtppro.zoho.eu EMAIL_PORT=587 EMAIL_HOST_USER=admin@<redacted>.xyz EMAIL_HOST_PASSWORD=mypassisnotthis EMAIL_USE_TLS=True EMAIL_USE_SSL=False And still in wger_server logs i see: smtplib.SMTPDataError: (553, b'Relaying disallowed as [email protected]')

TryCatchCrash avatar Dec 15 '22 21:12 TryCatchCrash

Hi hope I can help/throw a bit more info your way.

I've had the same: 'Requested action not taken: mailbox unavailable\nSender address has null MX', 'wger Workout Manager <[email protected]> error in the server logs when trying to send the verification email. But, using the sendtestemail to the same target email works as expected.

The from email has been changed from the default [email protected] to the correct version.

Using the docker version, downloaded today:

Exception in thread Thread-4 (send_email_thread):
Traceback (most recent call last):
  File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.10/threading.py", line 953, in run
    self._target(*self._args, **self._kwargs)
  File "/usr/local/lib/python3.10/dist-packages/django_email_verification/confirm.py", line 97, in send_email_thread
    msg.send()
  File "/usr/local/lib/python3.10/dist-packages/django/core/mail/message.py", line 298, in send
    return self.get_connection(fail_silently).send_messages([self])
  File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 131, in send_messages
    sent = self._send(message)
  File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 149, in _send
    self.connection.sendmail(
  File "/usr/lib/python3.10/smtplib.py", line 887, in sendmail
    raise SMTPSenderRefused(code, resp, from_addr)
smtplib.SMTPSenderRefused: (550, b'Requested action not taken: mailbox unavailable\nSender address has null MX', 'wger Workout Manager <[email protected]>')

I've not really dug through the code, just a bit of grep. I can see that the environmental setting FROM_EMAIL is trying to set the from email, but I've not gone through the code to see the order in which these are called etc.

$ grep -R -i '[email protected]'
wger/settings_global.py:    'EMAIL_FROM': 'wger Workout Manager <[email protected]>',
wger/settings.tpl:WGER_SETTINGS['EMAIL_FROM'] = 'wger Workout Manager <[email protected]>'

Can see that the FROM_EMAIL has tried to be set from the environmental setting, I've not looked into when this was set in relation to the verification email being called - not familiar with Django

$ grep -R -i 'FROM_EMAIL' *.py
settings.py:WGER_SETTINGS['EMAIL_FROM'] = f'wger Workout Manager <{env.str("FROM_EMAIL")}>'
settings.py:DEFAULT_FROM_EMAIL = WGER_SETTINGS['EMAIL_FROM']

Don't know if this helps at all.

ewenny avatar Dec 31 '22 14:12 ewenny

BTW the .tpl file is only used when calling wger create-settings the settings file used in docker is master/extras/docker/development/settings.py

rolandgeider avatar Jan 05 '23 13:01 rolandgeider

Hi, I seem to be experiencing this same issue.

My current mail settings (there are some extras cobbled together from bits I've found in various issues in this and the main wger repo);

ENABLE_EMAIL=True
EMAIL_HOST=smtp.mailersend.net
EMAIL_PORT=587
EMAIL_HOST_USER=****@****
EMAIL_HOST_PASSWORD=*****
EMAIL_USE_TLS=True
EMAIL_USE_SSL=False
DEFAULT_FROM_EMAIL=wger@******
FROM_EMAIL=wger@******
SERVER_EMAIL=wger@******

And the error is;

Exception in thread Thread-2 (send_email_thread):
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
self.run()
File "/usr/lib/python3.10/threading.py", line 953, in run
self._target(*self._args, **self._kwargs)
File "/usr/local/lib/python3.10/dist-packages/django_email_verification/confirm.py", line 97, in send_email_thread
msg.send()
File "/usr/local/lib/python3.10/dist-packages/django/core/mail/message.py", line 298, in send
return self.get_connection(fail_silently).send_messages([self])
File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 131, in send_messages
sent = self._send(message)
File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 149, in _send
self.connection.sendmail(
File "/usr/lib/python3.10/smtplib.py", line 908, in sendmail
raise SMTPDataError(code, resp)
smtplib.SMTPDataError: (450, b'The from.email must be verified. The from.email must be verified.')

The error is being returned by my SMTP provider so the SMTP credentials are definitely being picked up successfully, and on running;

python manage.py sendtestemail ****@******

The correct FROM_EMAIL defined in prod.env is used, the email is accepted by my SMTP provider and reaches it's destination.

Exporting the FROM_EMAIL environment variable within the container also displays the correct string set in prod.env. The only thing I can think would be causing this issue is the wger settings not successfully picking up the value in FROM_EMAIL, or losing it at some point along the way as the 'sendtestemail' command seems to grab it successfully as mentioned in the original post.

bobbobson52 avatar Jan 13 '23 10:01 bobbobson52

Saw what looked like it might be a typo in settings.py in another issue;

settings.py:WGER_SETTINGS['EMAIL_FROM'] = f'wger Workout Manager <{env.str("FROM_EMAIL")}>'

Made a copy of the file locally, removed a (maybe) erroneous 'f' and mounted within the container;

settings.py:WGER_SETTINGS['EMAIL_FROM'] = 'wger Workout Manager <{env.str("FROM_EMAIL")}>'

I verified this affected the file within the container, but emails sent by wger itself still fail

bobbobson52 avatar Jan 13 '23 11:01 bobbobson52

I couldn't set up email too. When I was using a mail server host with subdomainname EMAIL_HOST=smtp.blaa.blaa useing a provider without that worked... EMAIL_HOST=blaa.blaa

and the user I had bevor was like [email protected] and with the working provider its just blaa

maybe this helpes to sort this out. I'd prefer the mail host that is not working... :(

HerrFrutti avatar Aug 26 '23 13:08 HerrFrutti