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

Cannot send emails #12678

Open
darkbox opened this issue Oct 23, 2024 · 5 comments
Open

Cannot send emails #12678

darkbox opened this issue Oct 23, 2024 · 5 comments

Comments

@darkbox
Copy link

darkbox commented Oct 23, 2024

Expected Behavior

Allow to send user invitations via email

Actual Behavior

Every time I try I get this error add_message() argument must be an HttpRequest object, not 'NoneType'. (<class 'TypeError'>)

Steps to Reproduce the Problem

  1. Configure .env with email credentials
  2. Login and send invitation
  3. Got error.

Specifications

  • GeoNode version: Base Image is 4.3.1
  • Installation type: geonode-project without mods
  • Installation method: docker
  • Additional details: If I make a simple python script to send a test email with same credentials it works, but if I do it through the django docker container using the email backend gives an error saying the username or password are invalid (they are not).
@mattiagiupponi
Copy link
Contributor

did you try to wrap the username/password in the double quotes?

@darkbox
Copy link
Author

darkbox commented Oct 28, 2024

Already did with ="email" and ="password". No success.
As additional info, I'm using google smtp. The account has the unsecure app auth enabled.

# EMAIL Notifications
EMAIL_ENABLE=True
DJANGO_EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
DJANGO_EMAIL_HOST=smtp.gmail.com
DJANGO_EMAIL_PORT=587
DJANGO_EMAIL_HOST_USER="[email protected]"
DJANGO_EMAIL_HOST_PASSWORD="password_edited"
DJANGO_EMAIL_USE_TLS=True
DJANGO_EMAIL_USE_SSL=False
DEFAULT_FROM_EMAIL='Soporte <[email protected]>' # eg Company <[email protected]>

@darkbox
Copy link
Author

darkbox commented Nov 4, 2024

Here, If a test sending an email with same credentials with the following python script it works fine:

import smtplib

server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('[email protected]', 'password_edited')
server.sendmail('[email protected]', '[email protected]', 'Subject: Test Email\n\nThis is a test email.')
server.quit()
print('Test email sent!')

But as said earlier it does not work with Geonode. For example, if I try:

docker exec -it django4my_geonode python manage.py shell -c "from django.core.mail import send_mail; send_mail('TEST GEONODE EMAIL', 'Test Message', '[email protected]', ['[email protected]'], fail_silently=False)"

I get the following output error:

Traceback (most recent call last):
  File "/usr/src/my_geonode/manage.py", line 31, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python3.10/dist-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/usr/local/lib/python3.10/dist-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 412, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/local/lib/python3.10/dist-packages/django/core/management/base.py", line 458, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python3.10/dist-packages/django/core/management/commands/shell.py", line 117, in handle
    exec(options["command"], globals())
  File "<string>", line 1, in <module>
  File "/usr/local/lib/python3.10/dist-packages/django/core/mail/__init__.py", line 87, in send_mail
    return mail.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 127, in send_messages
    new_conn_created = self.open()
  File "/usr/local/lib/python3.10/dist-packages/django/core/mail/backends/smtp.py", line 94, in open
    self.connection.login(self.username, self.password)
  File "/usr/lib/python3.10/smtplib.py", line 750, in login
    raise last_exception
  File "/usr/lib/python3.10/smtplib.py", line 739, in login
    (code, resp) = self.auth(
  File "/usr/lib/python3.10/smtplib.py", line 662, in auth
    raise SMTPAuthenticationError(code, resp)
smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. For more information, go to\n5.7.8  https://support.google.com/mail/?p=BadCredentials 2adb3069b0e04-53c7bc9c966sm1556331e87.111 - gsmtp')

My question is why? Is the same email and credentials. This is driving me crazy :(

I've checked the env variables inside the container just to make sure, and they exists with correct values.

@ridoo
Copy link
Contributor

ridoo commented Nov 6, 2024

I guess that Django Email is considered by Google as less secure application (LSA). Google has trying to phase out such logins since 2019 and this is still ongoing. However, if you are trying to configure simple username and password you should consider creating an app password and use this instead.

@darkbox
Copy link
Author

darkbox commented Nov 11, 2024

I will try it and report back.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants