import urllib.request
import urllib.error
import json
import time

email = f"smtp_tester_{int(time.time())}@example.com"
url = "http://localhost:8000/api/v1/auth/register"
payload = {
    "email": email,
    "password": "TestPassword123!",
    "first_name": "Test",
    "last_name": "SMTP",
    "region_code": "HU",
    "lang": "hu"
}

data = json.dumps(payload).encode('utf-8')
req = urllib.request.Request(url, data=data, headers={'Content-Type': 'application/json'})

try:
    print(f"Registering: {email}")
    resp = urllib.request.urlopen(req, timeout=20.0)
    print(f"Status: {resp.status}")
    print(f"Response: {resp.read().decode('utf-8')}")
except urllib.error.HTTPError as e:
    print(f"HTTPError: {e.code}")
    print(f"Response: {e.read().decode('utf-8')}")
except Exception as e:
    print(f"Error: {e}")
