I am not receiving ...
 
Notifications
Clear all

I am not receiving account verification email.

20 Posts
2 Users
0 Reactions
24 Views
0
Topic starter

Reference Section 13:

Account Activation – Decode User PK & Activate the User | Expire Link

I am not receiving an account verification email.

```

# verification email
from django.contrib.sites.shortcuts import get_current_site
from django.template.loader import render_to_string
from django.utils.http import urlsafe_base64_encode, urlsafe_base64_decode
from django.utils.encoding import force_bytes
from django.contrib.auth.tokens import default_token_generator
from django.core.mail import EmailMessage
 
views.py
 
            # user activation
            current_site = get_current_site(request)
            mail_subject = 'Please activate your account'
            message = render_to_string('accounts/account_verification_email.html', {
                'user': user,
                'domain': current_site,
                'uid': urlsafe_base64_encode(force_bytes(user.pk)),
                'token': default_token_generator.make_token(user),
            })
            to_email = email
            send_email = EmailMessage(mail_subject, message, to=[to_email])
            messages.success(request, 'Registration successful')
            return redirect('register')

    else:
        form = RegistrationForm()
    context = {
        'form':form,
    }
    return render(request, 'accounts/register.html', context)
 
def activate(request, uidb64, token):
    return HttpResponse('Okay')

```

urls.py

```

path('activate/<uidb64>/<token>/', views.activate, name='activate'),

```

account_verification_mail.html

```

{% autoescape off %}
Hi {{ user.user_name }},
Please click on below link to confirm your registration.

http://{{ domain }}{% url 'activate' uidb64=uid token=token %}
If you think it's not you, please ignore this email.
{% endautoescape %}
```
8 Answers
0

Hi Ejaz Ali Inayat,
Your email is not being sent to the user because there is a mistake in your code. You forgot to add the following line:

send_email.send()

The send() function is responsible for sending emails. If you don't use it, your email will not be sent. So, after this code:

to_email = email
send_email = EmailMessage(mail_subject, message, to=[to_email])

Make sure to add:

send_email.send()

I hope this resolves your issue. If you face any other issues, feel free to ask.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 24/01/2025 11:15 pm

@mohaiminul-Islam Sir, I am now receiving the following error:

self.connection.starttls(keyfile=self.ssl_keyfile, certfile=self.ssl_certfile)
TypeError: SMTP.starttls() got an unexpected keyword argument 'keyfile'

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 24/01/2025 11:23 pm

@mohaiminul-islam My Python 3.12.4
Django 3.1

0

Hi Ejaz Ali Inayat

Your issue is related to SMTP configuration. The SMTP service is encountering an unexpected argument named 'keyfile.' Please ensure that your SMTP settings are correct.

If you're still facing issues, please share:

  1. A screenshot of your SMTP configuration code.
  2. A screenshot of the error message.
  3. And your project's updated Git repository.

This will help in diagnosing and resolving the problem more effectively.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 31/01/2025 8:01 pm

@mohaiminul-islam I have attached two screenshots and also updated the git repository.
A screenshot of your SMTP configuration code.
A screenshot of the error message.
updated Git repository.

https://github.com/webextolcollege/greatkart-djangoproject.git

0

Hi  Ejaz Ali Inayat
I have run your code on my system and replaced your SMTP configuration with mine. The code works properly. I suggest you create a new app password from your Google account, add it, and check again. It should work since it is working on my system. If you still face the issue after following these steps, let me know, and we will try to help you further.

This post was modified 2 weeks ago by Mohaiminul - Team Rathan
Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 02/02/2025 9:45 pm

@mohaiminul-islam Sir, on my system the issue remain the same "TypeError at /accounts/register/
SMTP.starttls() got an unexpected keyword argument 'keyfile'"

0

 Hi Ejaz Ali Inayat ,

The same issue you're facing after providing the correct SMTP credentials could be another reason.However, I noticed in your earlier comment that you're using:

  • Python 3.12.4
  • Django 3.1

Django 3.1 is not officially compatible with Python 3.12. To resolve this, please upgrade your Django version and update your related packages. After doing so, test your project again.

To upgrade Django, run the following command:

pip install --upgrade django

Please let me know the results after following these steps.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 04/02/2025 12:19 am

@mohaiminul-islam Sir, now the following error appears

raise SMTPSenderRefused

0

 Hi Ejaz Ali Inayat , This error occurs because SMTP server authentication is failing. You are using a Google App Password to send an email via Google's SMTP server, but the credentials are incorrect. This is the only reason for the error shown in the screenshot you provided.

Please check your credentials, and if the issue persists, try using a different email account. Verify the details and let me know if you need further assistance.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 06/02/2025 1:11 am

@mohaiminul-islam Sir, the issue remains the same

0

 Ejaz Ali Inayat

If you’re still facing the issue, please share your project zip file, including requirements.txt and the database dump.

Follow these steps to generate the required files:

1. Create requirements.txt

Activate your virtual environment:

.\YourEnvName\Scripts\activate

Then, generate the requirements.txt file by running:

pip freeze > requirements.txt

2. Create a Database Dump

Run the following command in your terminal to export your database:

python manage.py dumpdata > backup.json

3. Zip Your Project

Once you've generated requirements.txt and backup.json, zip your entire project folder along with these files.

After completing these steps, send us the zipped file . We will review it and try to fix your issue.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 07/02/2025 12:11 am

@mohaiminul-islam Sir, both files regarding SMTP server authentication are failing and are attached

IMG 1866 rathank.com Mohaiminul - Team Rathan 10/02/2025 1:46 pm

Ejaz Ali Inayat , Please also attach the ZIP file of your whole project.

Ejaz Ali Inayat Ejaz Ali Inayat Topic starter 10/02/2025 11:30 pm

@mohaiminul-islam Sir, I have attached the zip file of project for your kind cooperation

0
Topic starter

https://qaedpk-my.sharepoint.com/:u:/g/personal/3460322558995_qaed_edu_pk/EbxQG2kKnt9GuBhws-5lNmoBW1ufxsVsemYViInuO27BrQ?e=ysjv8l

Sir, I have shared the link to a zip file of my project. Now Sir, I need your kind cooperation

 

0

Ejaz Ali Inayat ,

Why is your SMTP configuration password empty? I just tested your project using my credentials, and it is working properly.

Please share your Google App Password with us so we can identify the actual error. If you have concerns about sharing your current account credentials, you can use a different account and provide those credentials instead.

If you prefer not to share them publicly, please send them via email to mohaiminul.islam@appzoneit.com.

We will try to resolve your issue as soon as possible.

Share: