|
|
|
@ -82,7 +82,19 @@ def environment_callback(request): |
|
|
|
|
|
|
|
|
|
|
|
def send_email(recipient, code): |
|
|
|
from apps.account.tasks import send_resend_email_task |
|
|
|
import requests |
|
|
|
from django.conf import settings |
|
|
|
|
|
|
|
if not settings.RESEND_API_KEY: |
|
|
|
print("RESEND_API_KEY is not set in settings.") |
|
|
|
return False |
|
|
|
|
|
|
|
url = "https://api.resend.com/emails" |
|
|
|
headers = { |
|
|
|
"Authorization": f"Bearer {settings.RESEND_API_KEY}", |
|
|
|
"Content-Type": "application/json", |
|
|
|
} |
|
|
|
|
|
|
|
subject = 'Verification Code' |
|
|
|
html_content = f""" |
|
|
|
<div style="font-family: Arial, sans-serif; max-width: 600px; margin: 0 auto; padding: 20px; border: 1px solid #e0e0e0; border-radius: 10px;"> |
|
|
|
@ -97,8 +109,21 @@ def send_email(recipient, code): |
|
|
|
<p style="font-size: 12px; color: #999; text-align: center;">Sent via Resend API</p> |
|
|
|
</div> |
|
|
|
""" |
|
|
|
send_resend_email_task.delay(recipient, subject, html_content) |
|
|
|
|
|
|
|
payload = { |
|
|
|
"from": settings.RESEND_FROM_EMAIL, |
|
|
|
"to": recipient, |
|
|
|
"subject": subject, |
|
|
|
"html": html_content, |
|
|
|
} |
|
|
|
|
|
|
|
try: |
|
|
|
response = requests.post(url, headers=headers, json=payload) |
|
|
|
response.raise_for_status() |
|
|
|
return True |
|
|
|
except Exception as e: |
|
|
|
print(f"Failed to send email via Resend: {str(e)}") |
|
|
|
return False |
|
|
|
|
|
|
|
|
|
|
|
def is_valid_email(email): |
|
|
|
|