language-learning-app/api/app/outbound/scaleway_tem/tem_client.py

30 lines
1.1 KiB
Python
Raw Normal View History

import httpx
_TEM_API_URL = "https://api.scaleway.com/transactional-email/v1alpha1/regions/{region}/emails"
class ScalewayTEMClient:
def __init__(self, secret_key: str, from_address: str, project_id: str, region: str = "fr-par") -> None:
self._secret_key = secret_key
self._from_address = from_address
self._project_id = project_id
self._url = _TEM_API_URL.format(region=region)
async def send_email(self, to: str, subject: str, html_body: str) -> None:
async with httpx.AsyncClient() as client:
response = await client.post(
self._url,
headers={
"X-Auth-Token": self._secret_key,
"Content-Type": "application/json",
},
json={
"project_id": self._project_id,
"from": {"email": self._from_address},
"to": [{"email": to}],
"subject": subject,
"html": html_body,
},
)
response.raise_for_status()