Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting up email #35

Open
rolandgeider opened this issue Oct 25, 2022 Discussed in #33 · 9 comments
Open

Setting up email #35

rolandgeider opened this issue Oct 25, 2022 Discussed in #33 · 9 comments
Labels
bug Something isn't working

Comments

@rolandgeider
Copy link
Member

It seems the FROM_EMAIL is getting lost somewhere:

Discussed in #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 wger@example.com')

FROM_EMAIL is set to admin@<mydomain.ext>

Am I doing something wrong or is this a bug?

@rolandgeider rolandgeider added the bug Something isn't working label Oct 25, 2022
@rolandgeider
Copy link
Member Author

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 user1234@server.com"

ENABLE_EMAIL=True
EMAIL_HOST=server.com
EMAIL_PORT=587
EMAIL_HOST_USER=user@server.com
EMAIL_HOST_PASSWORD=1234
EMAIL_USE_TLS=True
EMAIL_USE_SSL=False

SERVER_EMAIL=user5678@server.com
FROM_EMAIL=user1234@server.com

@TryCatchCrash
Copy link

@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.

@rolandgeider
Copy link
Member Author

Oh yes, looks like you runned into wger-project/wger#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 (wger-project/wger#1206)

@TryCatchCrash
Copy link

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 wger@example.com')

@ewenny
Copy link

ewenny commented Dec 31, 2022

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 <wger@example.com>
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 ...@example.com 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 <wger@example.com>')

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 'wger@example.com'
wger/settings_global.py:    'EMAIL_FROM': 'wger Workout Manager <wger@example.com>',
wger/settings.tpl:WGER_SETTINGS['EMAIL_FROM'] = 'wger Workout Manager <wger@example.com>'

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.

@rolandgeider
Copy link
Member Author

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

@bobbobson52
Copy link

bobbobson52 commented Jan 13, 2023

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
Copy link

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

rolandgeider added a commit to wger-project/wger that referenced this issue Jan 26, 2023
@HerrFrutti
Copy link

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 blaa@blaa.blaa 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... :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants