Spaces:
Sleeping
Sleeping
axeronis
feat: Configure Resend for email with smart fallback (onboarding@resend.dev) and fix email tasks
29e7a84 Download backend/app/tasks/email.py from axeronis/microfunnel-api: direct link, hf CLI and curl.
- Browser
- Download file 890 Bytes
-
https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/tasks/email.py
- Command line
-
hf download hf://spaces/axeronis/microfunnel-api/backend/app/tasks/email.py
-
curl -L -o email.py https://huggingface.co/spaces/axeronis/microfunnel-api/resolve/main/backend/app/tasks/email.py
890 Bytes
| from app.worker import celery_app | |
| from app.services.email import email_service | |
| from app.models.lead import Lead # If needed, but usually we pass primitive types (emails, subject, body) to tasks | |
| import asyncio | |
| from typing import List, Optional | |
| def send_email_task(to_email: str, subject: str, html_content: str): | |
| """ | |
| Background task to send email using async EmailService. | |
| """ | |
| try: | |
| # Create a new event loop for this thread/task | |
| loop = asyncio.new_event_loop() | |
| asyncio.set_event_loop(loop) | |
| # Run the async service method | |
| loop.run_until_complete(email_service.send_email( | |
| to=[to_email], | |
| subject=subject, | |
| html_body=html_content | |
| )) | |
| loop.close() | |
| return f"Email sent to {to_email}" | |
| except Exception as e: | |
| return f"Failed to send email: {e}" | |