I have the following error when trying to signup new user but if i change the following line : EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
to : EMAIL_BACKEND = ‘django.core.mail.backends.console.EmailBackend’
it’s running correctly and sending me the urls in the console
the error :
ConnectionRefusedError at /accounts/signup/
[WinError 10061] No connection could be made because the target machine actively refused it
Exception Value:
[WinError 10061] No connection could be made because the target machine actively refused it
Exception Location:
C:\Users\20155\AppData\Local\Programs\Python\Python311\Lib\socket.py, line 836, in create_connection
Raised during:
allauth.account.views.SignupView
Keep in your mind it gives me an error but it still working if i go to the admin panel the user will be shown but if i tried to login it will refuse it
what are your other
EMAIL_
settings in your settings file? That connection refused error is frequently caused by not being able to connect to the smtp server.
The other issue:
ahmedesmail07:
if i go to the admin panel the user will be shown but if i tried to login it will refuse it
Might be caused by the user object not being created correctly. You’ll want to check the user object in the admin in more detail to ensure that it’s not just shown, but that all the data is correct.
This is my email setting :
ACCOUNT_AUTHENTICATION_METHOD = “username_email”
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = “mandatory”
EMAIL_BACKEND = ‘django.core.mail.backends.smtp.EmailBackend’
EMAIL_HOST = ‘
smtp.sendgrid.com
’
EMAIL_FROM = ‘[email protected]’
EMAIL_HOST_USER = ‘apikey’
EMAIL_HOST_PASSWORD = ‘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’
EMAIL_PORT = 587
EMAIL_USE_TLS = True
From the sendgrid’s
smtp docs page
:
SendGrid accepts unencrypted and TLS connections on ports
25
,
587
, &
2525
. You can also connect via SSL on port
465
.
Seems sendgrid accepts only unencrypted connections on port 587. You could also try SSL with port 465.
What I would suggest is that you start with a small self-contained python script to send emails, and run it to try and send an email. It’s going to be easier to test and debug than running everything through Django. Once you’ve got that working, then it becomes easy to configure Django appropriately.
html_content = "This is a test email."
sg = sendgrid.SendGridAPIClient(apikey=settings.SENDGRID_API_KEY)
from_email = Email("Test User <
[email protected]>")
to_email = Email("
[email protected]")
content = Content("text/html", html_content)
mail = Mail(from_email, "Subject line.", to_email, content)
_ = sg.client.mail.send.post(request_body=mail.get())
except Exception as e:
print(e)
I just extracted that from an old project, it is not designed to be copy/pasted.
Excuse me for jumping in, I was just was lurking and realised I could possibly help.
i tried as you said sir but i got this error :
SMTPDataError at /api/dj-rest-auth/registration/
(550, b’The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit
Sender Identity | Twilio
to see the Sender Identity requirements’)
Exception Value:
(550, b’The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit
Sender Identity | Twilio
to see the Sender Identity requirements’)
but i checked my single sender was verified
gcain:
Sendgrid has a package/library that you use, I don’t believe it works via SMTP like a typical mail server.
That is not an accurate statement. See
SMTP Service | SMTP Relay | Start for Free | SendGrid
but my single sender was confirmed and my current address is the same in the settings of the provider and this is my code :
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_EMAIL_VERIFICATION = ‘mandatory’
LOGIN_ON_EMAIL_CONFIRMATION = True
EMAIL_BACKEND = “django.core.mail.backends.smtp.EmailBackend”
EMAIL_HOST = “
smtp.sendgrid.net
”
EMAIL_FROM = “
[email protected]
”
EMAIL_HOST_USER = “apikey”
EMAIL_HOST_PASSWORD = “SG.INQQHB4eTTmNNPzoyoN9kA.XbHXTeskI-7o9KujIYHwnU05P2mjOomUdVmk9NPaXXk”
EMAIL_PORT = 587
EMAIL_USE_TLS = True