How to send Email verification codes to user in Firebase using Python?

Viewed 1119

I'm making a KivyMD App and I want to send email verification code when an user is registered to the application. I'm using a firestore database with python for this project. But I don't have an idea to do that. The registration process is

  1. User sign up to the application with his email address.
  2. an email contains a code (with random numbers - OTP Code) should be send to the user's email.
  3. After user enters the correct verification code he should be registered in the application.

Can this be done with the way I expected? Or are there other better ways? Please help me Friends. Thank you in advance...

2 Answers

In order to send verification link on email you have to setup smpt server

import firebase_admin
from firebase_admin import credentials
from firebase_admin import auth
import smtplib
s = smtplib.SMTP('protonmail.com', 1025)
s.starttls()
s.login("your email", "pass0")
cred = credentials.Certificate('you_Secret.json')
firebase_admin.initialize_app(cred)


# creating the user
email = input('Please enter your email address : ')
password = input("Please enter your password : ")

user = auth.create_user(email=email, password=password )
link = auth.generate_email_verification_link(email, action_code_settings=None)
message = link
print(link)
s.sendmail("sender email", "reciever email", message)

# terminating the session
s.quit()

OUTPUT

link:https://hospitile.firebaseapp.com/__/auth/action?mode=verifyEmail&oobCode=_yM6YyEBt7e5Fyokjpbt4EUMw4eZzAe41n-t2oS-tNYAAAF9eZ-hnQ&apiKey=AIzaSyBJld5O_s09YVHoQ0ci7g3N3S-0DYjuH0U&lang=en

enter image description here

And when you click on that link you will be prompted to new tab below

enter image description here

Related