Forums

Djoser reset password email not sent from pythonanywher

Hi, I've some issues getting the reset password email sent from my pythonanywhere instance. The reset password email should contain a link and when the user.

It works fine in the local envirement with the same settings and version of the code. I recieve an email with the correct content. When trying to do the same from pythonanywhere i dont recieve any mail. My djoser settings are

settings.py

MAIL_HOST = 'smtp.gmail.com'
EMAIL_HOST_USER = SECRET
EMAIL_HOST_PASSWORD = SECRET
EMAIL_PORT = 587
EMAIL_USE_TLS = True

SIMPLE_JWT = {
  'AUTH_HEADER_TYPES': ('JWT',),
}
DJOSER = {
  "USER_ID_FIELD": "username",
  "LOGIN_FIELD": "email",
  "SEND_ACTIVATION_EMAIL": True,
  "ACTIVATION_URL": "activate/{uid}/{token}",
  "PASSWORD_RESET_CONFIRM_URL": "reset_password/{uid}/{token}", # the reset link 
 }

urls.py

    path('auth/', include('djoser.urls')),
    path('auth/', include('djoser.urls.jwt')),

Has anywone had the same problem? I don't see any errors in the logs.

The user that I try to reset in is initated the same way in both( local and pythonanywhere) enviroements by a POST request.

I'm digging a bit deeper in the source code of djoser and it appears that i'm not getting the user correcty set. in djoser/views.py

    def reset_password(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        user = serializer.get_user()

Will dig a bit deeper and se what is causing the problem

I found the problem. In my local enviroment I had another user with the same email registered as the email I used for another username. If I set the email field on the django User it all works fine.

I originally had the same issue in both enviroments but it did not appear in my local setup.

Glad you could solve that!