Skip to content

Commit

Permalink
fix mypy issues in lib/email.py
Browse files Browse the repository at this point in the history
  • Loading branch information
khoaguin committed Dec 16, 2024
1 parent 437507e commit ef92cd8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions syftbox/lib/email.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Optional

import httpx
from jinja2 import Template
from loguru import logger
Expand Down Expand Up @@ -128,7 +130,7 @@
"""


def send_token_email(server_settings, user_email: str, token: str):
def send_token_email(server_settings: ServerSettings, user_email: str, token: str) -> None:
template = Template(token_email_template)
body = template.render(email=user_email, token=token)
send_email(
Expand All @@ -146,14 +148,17 @@ def send_email(
subject: str,
body: str,
mimetype: str = "text/html",
):
) -> Optional[dict]:
payload = {
"personalizations": [{"to": [{"email": receiver_email}]}],
"from": {"email": SENDER_EMAIL},
"subject": subject,
"content": [{"type": mimetype, "value": body}],
}

if server_settings.sendgrid_secret is None:
raise ValueError("Sendgrid secret is not configured")

headers = {
"Authorization": f"Bearer {server_settings.sendgrid_secret.get_secret_value()}",
"Content-Type": "application/json",
Expand All @@ -166,3 +171,4 @@ def send_email(
return {"success": True, "status_code": response.status_code}
except httpx.HTTPError as e:
logger.error(str(e))
return None

0 comments on commit ef92cd8

Please sign in to comment.