Having followed the...
 
Notifications
Clear all

Having followed the tutorial till this stage, I am stuck at the SEND VERIFICATION EMAIL. Even looking at the project git repository, I am still receiving error messages

6 Posts
3 Users
0 Reactions
192 Views
0
Topic starter

/// utils.py ///

# accounts/utils.py
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
from django.utils.encoding import force_bytes
from django.contrib.auth.tokens import default_token_generator
from django.core.mail import EmailMessage

def detectUser(user):
if user.role == 1:
    redirectUrl = 'vendorDashboard'
return redirectUrl
elif user.role == 2:
    redirectUrl = 'custDashboard'
return redirectUrl
elif user.role == Noneand user.is_superadmin:
    redirectUrl = '/admin'
return redirectUrl

def send_verification_email(request, user):
  current_site = get_current_site(request)
  mail_subject = 'Please activate your account'
  message = render_to_string('accounts/emails/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 = user.email
  mail = EmailMessage(mail_subject, message, to=[to_email])  
  mail.send()
 
 
///Error messages from browser//
 
C:\Users\Yanga\Desktop\GAAS\accounts\views.py, line 58, in registerUser
  1.       user = User.objects.create_user(first_name=first_name, last_name=last_name, username=username, email=email, password=password)
  2.       user.role = User.CUSTOMER
  3.       user.save()
  4.       
  5.       #Send verification email
  6.       mail_subject = 'Please activate your account'
  7.       email_template = 'accounts/emails/account_verification_email.html'
  1.       send_verification_email(request, user)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  1.       messages.success(request, "Your account has been registered successfully!")
  2.       return redirect('registerUser')
  3.     else:
  4.       print('invalid form')
  5.       print(form.errors)
  6.   else:   


 

C:\Users\Yanga\Desktop\GAAS\accounts\utils.py, line 32, in send_verification_email

  1.     'user': user,
  2.     'domain': current_site,
  3.     'uid': urlsafe_base64_encode(force_bytes(user.pk)),
  4.     'token': default_token_generator.make_token(user),
  5.   })
  6.   to_email = user.email
  7.   mail = EmailMessage(mail_subject, message, to=[to_email])  
  1.   mail.send()
    
This topic was modified 5 months ago by Ibrahim Salami
5 Answers
0
Topic starter

https://github.com/hizeetech/gaas.git

0

Hi Ibrahim Salami ,

The issue you are facing occurs when your SMTP configuration is incorrect. Please check your SMTP settings to ensure they are correct. Additionally, the GitHub repository link you provided is incorrect.

If you are unable to fix the issue, please provide a screenshot of your SMTP configuration and share a ZIP file link to your project so we can assist you in resolving the problem.

88b9c95a10c14f1c07b5c2c551a2538a9f6aa5d7a6c5ec1126b0ddcd11464148?s=36&d=mm&r=g rathank.com Ibrahim Salami Topic starter 12/02/2025 5:03 pm

@mohaiminul-islam Thanking you so much. This has been resolved. I want to believe the issue is from gmail.

0
Topic starter

An invitation has been sent to you as collaborator on the repository.
Thanks

0

I am having an error with respect to the email verification set up

0

Samuel Bakare , The issue you are facing is due to an incorrect SMTP configuration. Please fix it. Your SMTP configuration should look like this:

  1. EMAIL_HOST=smtp.gmail.com
  2. EMAIL_PORT=587
  3. EMAIL_HOST_USER=your_email@gmail.com
  4. EMAIL_HOST_PASSWORD=your_email_app_password
  5. EMAIL_USE_TLS=True
  6. DEFAULT_FROM_EMAIL=foodOnline Marketplace <foodonline576@gmail.com>

Here are the steps to generate a Google App Password:
1. Go to your Gmail account.

2. In the top right, press a circular icon with your first name's letter on it or your profile image.

3. Below the salutation, you will see "Manage your Google Account".

4. Choose it.

5. In the new window (in the top left) you will see the category called "Security".

6. Press it.

7. Just in the center (scroll a bit down), you will see a table called "How you sign in to Google". Click 2-step verification and follow the instructions there.

8. After following the instructions (when you have set the verification), press the "2-step verification" forward arrow again (if you did it right, there will be a green tick).

9. Enter your password.

10. You will be redirected to a new page where you need to scroll down, give a name to your app, press "Generate App Password" and copy it into your .env file.

11. By the way, EMAIL_HOST_USER=foodonline@gmail.com(or any other email) must be WITHOUT ''django'.

12. Your EMAIL_HOST_PASSWORD must be WITHOUT spaces and commas.

 

Your email configuration could look similar to this:
# Email configuration

EMAIL_HOST=smtp.gmail.com

EMAIL_PORT=587

EMAIL_HOST_USER=foodonline@gmail.com

EMAIL_HOST_PASSWORD=cdtkgthwnapzlcgy

If you face any issues or experience any inconvenience, please let us know — we’re here to help you.

 

Share: