feat: Add email notifications for all notification types

Sends HTML email via Gmail SMTP when notifications are created.
Supports multi-language (en/ko/mn/ru) based on user country.
Runs in background thread to avoid blocking requests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
AutonetSellCar Deploy
2026-02-18 09:55:12 +09:00
parent 436712367c
commit 46973c8508
2 changed files with 206 additions and 1 deletions

View File

@@ -10,6 +10,7 @@ from ..schemas.notification import (
NotificationCreate, NotificationResponse,
NotificationListResponse, NotificationMarkRead
)
from ..services.email_service import send_notification_email
from .auth import get_current_user
router = APIRouter(prefix="/notifications", tags=["notifications"])
@@ -29,7 +30,7 @@ def create_notification(
related_id: Optional[int] = None,
related_type: Optional[str] = None
) -> Notification:
"""Create a new notification"""
"""Create a new notification and send email"""
notification = Notification(
user_id=user_id,
notification_type=notification_type,
@@ -42,6 +43,23 @@ def create_notification(
db.add(notification)
db.commit()
db.refresh(notification)
# Send email notification (background thread, non-blocking)
try:
user = db.query(User).filter(User.id == user_id).first()
if user and user.email:
send_notification_email(
to_email=user.email,
notification_type=notification_type,
title=title,
message=message,
link=link,
user_name=user.name,
user_country=user.country,
)
except Exception as e:
print(f"[WARN] Email notification failed for user {user_id}: {e}")
return notification