diff --git a/example.env b/example.env index 2b20f14..a66851d 100644 --- a/example.env +++ b/example.env @@ -7,3 +7,5 @@ DATABASE_NAME="cloud-api" DATABASE_PORT="5432" DATABASE_HOSTNAME="localhost" DATABASE_CREDENTIALS="user:password" + +LETTERMINT_API_TOKEN="" \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml index 08a9729..bd23ff7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ dependencies = [ "itsdangerous>=2.2.0", "jinja2>=3.1.6", "joserfc>=1.6.7", + "lettermint>=2.0.0,<3.0.0", "psycopg[binary]>=3.3.4", "pydantic>=2.13.4", "pydantic-settings>=2.14.1", @@ -33,6 +34,7 @@ line-length = 92 [tool.ruff.format] quote-style = "double" +indent-style = "tab" [tool.uv] add-bounds = "major" diff --git a/src/config.py b/src/config.py index e8b9ec2..6ebfcf5 100644 --- a/src/config.py +++ b/src/config.py @@ -36,6 +36,8 @@ class Config(CustomBaseSettings): DATABASE_HOSTNAME: str = "localhost" DATABASE_CREDENTIALS: SecretStr = SecretStr(":") + LETTERMINT_API_TOKEN: SecretStr = SecretStr("") + settings = Config() diff --git a/src/utils.py b/src/utils.py index e3bdb25..b314d61 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,3 +1,4 @@ +from lettermint import Lettermint, ValidationError from datetime import datetime, timezone from joserfc import jwt, jwk, errors @@ -38,6 +39,21 @@ async def verify_email_token(user_model, token): async def send_email(recipient: str, subject: str, body: str): - print(recipient) - print(subject) - print(body) + lettermint = Lettermint(api_token=settings.LETTERMINT_API_TOKEN.get_secret_value()) + + if settings.ENVIRONMENT.is_testing or settings.ENVIRONMENT == "local": + recipient = "ok@testing.lettermint.co" + + try: + response = ( + lettermint.email.from_("noreply@sr2.uk") + .to(recipient) + .subject(subject) + .text(body) + .send() + ) + + print(response.status_code) + except ValidationError: + # Error thrown if domain not approved for project + print("Lettermint validation error") diff --git a/uv.lock b/uv.lock index d38688f..f4be9e1 100644 --- a/uv.lock +++ b/uv.lock @@ -215,6 +215,7 @@ dependencies = [ { name = "itsdangerous" }, { name = "jinja2" }, { name = "joserfc" }, + { name = "lettermint" }, { name = "psycopg", extra = ["binary"] }, { name = "pydantic" }, { name = "pydantic-settings" }, @@ -243,6 +244,7 @@ requires-dist = [ { name = "itsdangerous", specifier = ">=2.2.0" }, { name = "jinja2", specifier = ">=3.1.6" }, { name = "joserfc", specifier = ">=1.6.7" }, + { name = "lettermint", specifier = ">=2.0.0,<3.0.0" }, { name = "psycopg", extras = ["binary"], specifier = ">=3.3.4" }, { name = "pydantic", specifier = ">=2.13.4" }, { name = "pydantic-settings", specifier = ">=2.14.1" }, @@ -533,6 +535,18 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/c5/e4/bcf6718b5662894c6831f46296b73cd4b1a2e90c20b6d437e20c4997388c/joserfc-1.6.7-py3-none-any.whl", hash = "sha256:9e51e4a64840aa1734a058258e80a4480e2ff2d5686e480e7c92c954a92fbe05", size = 70603, upload-time = "2026-05-23T01:46:42.129Z" }, ] +[[package]] +name = "lettermint" +version = "2.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "httpx" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/e9/31/cf1ab1f066e48a40139bf5d90a12d657ffd90440f4f726ca4199f73f0275/lettermint-2.0.0.tar.gz", hash = "sha256:399d17c3a707a2515402245e0785534171c482cf83f9e763a6878aa4bf974e1a", size = 29415, upload-time = "2026-05-11T08:00:50.054Z" } +wheels = [ + { url = "https://files.pythonhosted.org/packages/e2/b5/13978fc95fdaf977c287ef6a956795717c6d74f74504dc3958ebaf8338f1/lettermint-2.0.0-py3-none-any.whl", hash = "sha256:39859fd9a66ef2c1729889befd3c261b29641e187247c7a0334c421961c88b47", size = 21303, upload-time = "2026-05-11T08:00:48.625Z" }, +] + [[package]] name = "mako" version = "1.3.12"