|
|
|
|
|
import os |
|
import secrets |
|
from mailjet_rest import Client |
|
|
|
|
|
MAILJET_API_KEY = os.environ.get("MAILJET_API_KEY") |
|
MAILJET_API_SECRET = os.environ.get("MAILJET_API_SECRET") |
|
|
|
|
|
mailjet = Client(auth=(MAILJET_API_KEY, MAILJET_API_SECRET)) |
|
|
|
def send_verification_email(to_email, verification_token): |
|
|
|
email_data = { |
|
'Messages': [ |
|
{ |
|
"From": { |
|
"Email": "[email protected]", |
|
"Name": "Your Name" |
|
}, |
|
"To": [ |
|
{ |
|
"Email": to_email, |
|
"Name": "User Name" |
|
} |
|
], |
|
"Subject": "Verify Your Email", |
|
"HTMLPart": f'Click <a href="https://gregniuki-loginauth.hf.space/verify/{verification_token}">here</a> to verify your email.' |
|
} |
|
] |
|
} |
|
|
|
|
|
try: |
|
response = mailjet.send.create(data=email_data) |
|
if response.status_code == 200: |
|
print("Verification email sent successfully.") |
|
else: |
|
print("Failed to send verification email.") |
|
except Exception as e: |
|
print(str(e)) |
|
|
|
def generate_verification_token(email): |
|
|
|
token = secrets.token_urlsafe(32) |
|
|
|
|
|
|
|
|
|
return token |