Skip to content

Commit

Permalink
feat: email handler
Browse files Browse the repository at this point in the history
  • Loading branch information
samderanova committed Dec 12, 2023
1 parent bc71e2d commit fe18485
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions apps/api/src/utils/email_handler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from enum import Enum
from typing import Protocol

from pydantic import EmailStr

from services import sendgrid_handler

IH_SENDER = ("[email protected]", "IrvineHacks 2024 Applications")


class ContactInfo(Protocol):
email: EmailStr
first_name: str
last_name: str


class Template(str, Enum):
# TODO: provide actual template IDs
CONFIRMATION_EMAIL = "d-2026cde7bebd45ad85723443808c5817"
GUEST_TOKEN = "d-b19f08e584cb4c0f97b55f567ee10afc"


async def send_application_confirmation_email(user: ContactInfo) -> None:
"""Send a confirmation email after a user submits an application.
Will propagate exceptions from SendGrid."""
await sendgrid_handler.send_email(
Template.CONFIRMATION_EMAIL,
IH_SENDER,
{
"email": user.email,
"first_name": user.first_name,
"last_name": user.last_name,
},
)


async def send_guest_login_email(email: EmailStr, passphrase: str) -> None:
"""Email login passphrase to guest."""
await sendgrid_handler.send_email(
Template.GUEST_TOKEN,
IH_SENDER,
{"email": email, "passphrase": passphrase},
)

0 comments on commit fe18485

Please sign in to comment.