Skip to content

Commit

Permalink
test mode logging support
Browse files Browse the repository at this point in the history
  • Loading branch information
4kimov committed Mar 6, 2024
1 parent f579d15 commit 73e68cc
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# CHANGELOG

**v0.1.0-alpha.3:**
- `README.md`: notice about test mode
- Support for test mode logging

**v0.1.0-alpha.2:**
- `README.md` cleanup (listing of components)
- `Image` component now requires only `src`; the other params are optional
Expand Down
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,18 @@ There are more examples in the [examples](examples) folder ✨
> [!NOTE]
> 🚧 **The SDK is not stable yet.** This API might change as more features are added. Please watch the repo for the changes in the [CHANGELOG](CHANGELOG.md).
## 🏗 Debugging

You can generate _test API keys_ by activating the **Test Mode** in your dashboard. By using these keys, you'll be able to view your fully rendered emails without actually sending them.

When you use a test API key in your SDK, the following output will appear in your logs when you try to send an email:

```log
Templateless [TEST MODE]: Emailed user@example.com, preview: https://tmpl.sh/ATMxHLX4r9aE
```

The preview link will display the email, but you must be logged in to Templateless to view it.

## 🔳 Components

Emails are crafted programmatically by making function calls. There's no dealing with HTML or drag-and-drop builders.
Expand Down Expand Up @@ -265,7 +277,7 @@ If you'd like your recipients to be able to read the email in a browser, you can

You can optionally provide the text for the link. If none is provided, default is used: "View in browser"

**This will make the email public to anyone that has access to the link.**
**Anyone who knows the link will be able to see the email.**

```python
content = (
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[project]
name = "templateless"
description = "Ship faster by sending elegant emails using just code"
version = "0.1.0-alpha.2"
version = "0.1.0-alpha.3"
readme = "README.md"
authors = []
license = { file = "LICENSE" }
Expand Down
9 changes: 8 additions & 1 deletion templateless/templateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,14 @@ def send_many(self, emails: list[Email]):
elif response.status_code == 500:
raise UnavailableError
elif response.status_code == 200:
emails_response = EmailResponse(emails=response.json().get("emails", []))
email_response = response.json()

for preview in email_response.get("previews", []):
print(
f"Templateless [TEST MODE]: Emailed {preview['email']}, preview: https://tmpl.sh/{preview['preview']}"
)

emails_response = EmailResponse(emails=email_response.get("emails", []))
return emails_response.emails
else:
raise UnknownError

0 comments on commit 73e68cc

Please sign in to comment.