Django: how to generate activate_url that Django allauth generates for email confirmation

耗尽温柔 提交于 2020-07-23 06:42:24

问题


Django allauth sends an account confirmation email with activate url which is {{activate_url}}. One example for this url is http://127.0.0.1:8000/accounts/confirm-email/NTM:1jfPhE:KyDCaadIYlHM23UbccSVcDnzdJU/. But I can't use allauth to handle for sending confirmation emails as I am using Gmail account for sending emails and Gmail is not allowing to send email with allauth because it was not secure enough. So I used Gmail API to send emails and using @receiver(user_signed_up) to send confirmation emails. But I want to allauth to handle the activation process and I see that allauth uses {{activate_url}} link for verifying the email for the account. How do I generate this {{activate_url}} so that I send the email with this link and allauth handles confirming email from there?

Update: To answer for a question in the comment below. I am using following settings for sending email in Django:

EMAIL_USE_TLS = True
EMAIL_HOST = 'smtp.gmail.com'
EMAIL_PORT = 587
EMAIL_HOST_USER = DEFAULT_FROM_EMAIL = '*****@*****.com'
EMAIL_HOST_PASSWORD = '********'

Then I am getting the following error.

smtplib.SMTPAuthenticationError: (535, b'5.7.8 Username and Password not accepted. Learn more at\n5.7.8  https://support.google.com/mail/?p=BadCredentials n25sm9623217qkk.76 - gsmtp')

username and password are correct. When I googled this issue I found out that Gmail is not allowing to send emails with low security apps. They used to have Turning ON option for low security apps but it looks like they don't have that option anymore.

来源:https://stackoverflow.com/questions/62123264/django-how-to-generate-activate-url-that-django-allauth-generates-for-email-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!