File size: 1,754 Bytes
80970f1
42bf4ff
bafa0db
 
 
 
 
abf966c
 
bafa0db
 
4e57d31
bafa0db
 
 
 
 
 
 
e163adf
bafa0db
 
 
 
 
 
 
 
 
ac01fc9
bafa0db
 
 
 
 
 
 
 
4e57d31
 
bafa0db
 
 
4e57d31
 
bafa0db
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#emailx.py

import os
import secrets
from mailjet_rest import Client

# Load Mailjet API keys from environment variables
MAILJET_API_KEY = os.environ['MAILJET_API_KEY']
MAILJET_API_SECRET = os.environ['MAILJET_API_SECRET']

# Create a Mailjet client
mailjet = Client(auth=(MAILJET_API_KEY, MAILJET_API_SECRET), version='v3.1')

def send_verification_email(to_email, verification_token):
    # Create the email message
    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.'
            }
        ]
    }

    # Send the email
    try:
        response = mailjet.send.create(data=email_data)
        if response.status_code == 200:
            print(response.status_code)
            print(response.json())
            print("Verification email sent successfully.")
        else:
            print("Failed to send verification email.")
            print(response.status_code)
            print(response.json())
    except Exception as e:
        print(str(e))

def generate_verification_token(email):
    # Generate a random token
    token = secrets.token_urlsafe(32)

    # You can associate this token with the provided email address in your database
    # For example, store it in a verification_tokens table with an expiration date

    return token