Files
api/src/emails/emails.py
T

55 lines
1.6 KiB
Python

from typing import Any
from fastapi_mail import MessageSchema, MessageType
from pydantic import EmailStr
class Email(MessageSchema):
template: str
def __init__(
self, to: list[EmailStr | str], subject: str, template: str, template_variables: dict, **data: Any
) -> None:
data['subtype'] = MessageType.html
data['recipients'] = to
data['template'] = template
data['template_body'] = template_variables
data['subject'] = subject + " | Polétání.cz"
super().__init__(**data)
class ContactFormEmail(Email):
def __init__(self, email_from: str, content: str):
super().__init__(
to=["michal@kvacek.cz"],
reply_to=[email_from],
subject="Zpráva z kontaktního formuláře",
template="contact_form.html",
template_variables={
"content": content,
"email_from": email_from
}
)
class WelcomeEmail(Email):
def __init__(self, to: EmailStr | str):
super().__init__(
to=[to],
subject="Vítej",
template="welcome.html",
template_variables={}
)
class ResetPasswordEmail(Email):
def __init__(self, to: EmailStr | str, reset_token: str, validity_hours: int):
super().__init__(
to=[to],
subject="Žádost o reset",
template="reset_password.html",
template_variables={
"token": reset_token,
"validity_hours": validity_hours,
}
)