Skip to content

Latest commit

 

History

History
41 lines (31 loc) · 945 Bytes

File metadata and controls

41 lines (31 loc) · 945 Bytes

simple mailing

from fastapi_pundra.common.mailer.mail import send_mail

await send_mail(
    subject="Hello, World!",
    to=["test@example.com"],
    template_name="welcome_email.html",
    context={"name": "John Doe"},
)

background mailing

from fastapi_pundra.common.mailer.mail import send_mail_background

await send_mail_background(
    background_tasks=background_tasks,
    subject="Hello, World!",
    to=["test@example.com"],
    template_name="welcome_email.html",
    context={"name": "John Doe"},
)

routing tips

  • if you want to send mail in background, you can use background_tasks in your route
from fastapi import BackgroundTasks

@router.post("/users/registration")
@dto(UserCreateSchema)
async def registration(request: Request, background_tasks: BackgroundTasks) -> JSONResponse:
    ...

note: background_tasks paramter will be after request parameter in your route