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 0ab7faa commit b43a849
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 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)
- Added `examples/confirm_email`
Expand Down
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ It's perfect for SaaS, web apps, mobile apps, scripts and anywhere you have to s
Use go get:

```bash
go get github.com/templateless/templateless-go@v0.1.0-alpha.2
go get github.com/templateless/templateless-go@v0.1.0-alpha.3
```

Then import the package into your own code:
Expand Down Expand Up @@ -97,6 +97,18 @@ There are more Go 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 @@ -248,7 +260,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.**

```go
templateless.NewContent().
Expand Down
2 changes: 1 addition & 1 deletion examples/simple/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func main() {

email, _ := templateless.NewEmail().
To(*templateless.NewEmailAddress(emailAddress)).
Subject("Hello 👋").
Subject("Hello").
Content(*content).
Build()

Expand Down
16 changes: 15 additions & 1 deletion templateless.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,21 @@ import (
"encoding/json"
"fmt"
"io"
"log"
"net/http"
"os"
)

type ObjectId = string

type EmailResponsePreview struct {
Email string `json:"email"`
Preview string `json:"preview"`
}

type EmailResponse struct {
Emails []ObjectId
Emails []ObjectId `json:"emails"`
Previews *[]EmailResponsePreview `json:"previews"`
}

type Templateless struct {
Expand Down Expand Up @@ -109,6 +116,13 @@ func (t *Templateless) SendMany(emails []Email) ([]ObjectId, *CustomError) {
return nil, UnknownError()
}

if emailResponse.Previews != nil {
for _, preview := range *emailResponse.Previews {
log.Printf("Templateless [TEST MODE]: Emailed %s, preview: https://tmpl.sh/%s\n",
preview.Email, preview.Preview)
}
}

return emailResponse.Emails, nil
default:
return nil, UnknownError()
Expand Down

0 comments on commit b43a849

Please sign in to comment.