Files

33 lines
1.3 KiB
Python
Executable File

import os
from sendgrid import SendGridAPIClient
from sendgrid.helpers.mail import Mail
from fastapi import BackgroundTasks
SENDGRID_API_KEY = os.getenv("SENDGRID_API_KEY")
FROM_EMAIL = os.getenv("FROM_EMAIL")
async def send_email_async(subject: str, to_email: str, content: str):
message = Mail(
from_email=FROM_EMAIL,
to_emails=to_email,
subject=subject,
plain_text_content=content
)
try:
sg = SendGridAPIClient(SENDGRID_API_KEY)
sg.send(message)
except Exception as e:
print(f"--- EMAIL ERROR: {e}")
def send_verification_email(background_tasks: BackgroundTasks, email: str, token: str):
subject = "Service Finder - Fiók aktiválása"
# Itt a valós domain nevedet kell használnod
verify_url = f"http://192.168.100.43:8000/api/v1/auth/verify/{token}"
content = f"Kérjük, kattints az alábbi linkre a regisztrációd véglegesítéséhez: {verify_url}"
background_tasks.add_task(send_email_async, subject, email, content)
def send_expiry_notification(background_tasks: BackgroundTasks, email: str, doc_name: str):
subject = f"FIGYELEM: {doc_name} hamarosan lejár!"
content = f"Tisztelt Felhasználó! Értesítjük, hogy a(z) {doc_name} dokumentuma 30 napon belül lejár."
background_tasks.add_task(send_email_async, subject, email, content)