From 4c3e0991a21ca2c0ff81c67bccffde9cffed8bd7 Mon Sep 17 00:00:00 2001 From: mohsentaba Date: Tue, 12 May 2026 18:35:46 +0330 Subject: [PATCH] email handles without celery --- apps/account/tasks.py | 31 ------------------------------- utils/__init__.py | 31 ++++++++++++++++++++++++++++--- 2 files changed, 28 insertions(+), 34 deletions(-) diff --git a/apps/account/tasks.py b/apps/account/tasks.py index abf14b4..3ea0628 100644 --- a/apps/account/tasks.py +++ b/apps/account/tasks.py @@ -158,35 +158,4 @@ def send_otp_code_whatsapp(phone_number, code): time.sleep(2) -@shared_task -def send_resend_email_task(recipient_list, subject, html_content): - """ - Sends an email using Resend API. - """ - if not settings.RESEND_API_KEY: - logger.error("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", - } - - payload = { - "from": settings.RESEND_FROM_EMAIL, - "to": recipient_list, - "subject": subject, - "html": html_content, - } - - try: - response = requests.post(url, headers=headers, json=payload) - response.raise_for_status() - logger.info(f"Email sent successfully to {recipient_list} via Resend.") - return response.json() - except Exception as e: - logger.error(f"Failed to send email via Resend: {str(e)}") - return False - diff --git a/utils/__init__.py b/utils/__init__.py index a5f6257..ee063eb 100644 --- a/utils/__init__.py +++ b/utils/__init__.py @@ -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"""
@@ -97,8 +109,21 @@ def send_email(recipient, code):

Sent via Resend API

""" - send_resend_email_task.delay(recipient, subject, html_content) - return True + + 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):