Skip to content

Commit b43a849

Browse files
committed
test mode logging support
1 parent 0ab7faa commit b43a849

File tree

4 files changed

+34
-4
lines changed

4 files changed

+34
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# CHANGELOG
22

3+
**v0.1.0-alpha.3:**
4+
- `README.md`: notice about test mode
5+
- Support for test mode logging
6+
37
**v0.1.0-alpha.2:**
48
- `README.md` cleanup (listing of components)
59
- Added `examples/confirm_email`

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ It's perfect for SaaS, web apps, mobile apps, scripts and anywhere you have to s
4040
Use go get:
4141

4242
```bash
43-
go get github.com/templateless/[email protected].2
43+
go get github.com/templateless/[email protected].3
4444
```
4545

4646
Then import the package into your own code:
@@ -97,6 +97,18 @@ There are more Go examples in the [examples](examples) folder ✨
9797
> [!NOTE]
9898
> 🚧 **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).
9999
100+
## 🏗 Debugging
101+
102+
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.
103+
104+
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:
105+
106+
```log
107+
Templateless [TEST MODE]: Emailed [email protected], preview: https://tmpl.sh/ATMxHLX4r9aE
108+
```
109+
110+
The preview link will display the email, but you must be logged in to Templateless to view it.
111+
100112
## 🔳 Components
101113

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

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

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

253265
```go
254266
templateless.NewContent().

examples/simple/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func main() {
2424

2525
email, _ := templateless.NewEmail().
2626
To(*templateless.NewEmailAddress(emailAddress)).
27-
Subject("Hello 👋").
27+
Subject("Hello").
2828
Content(*content).
2929
Build()
3030

templateless.go

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,21 @@ import (
55
"encoding/json"
66
"fmt"
77
"io"
8+
"log"
89
"net/http"
910
"os"
1011
)
1112

1213
type ObjectId = string
1314

15+
type EmailResponsePreview struct {
16+
Email string `json:"email"`
17+
Preview string `json:"preview"`
18+
}
19+
1420
type EmailResponse struct {
15-
Emails []ObjectId
21+
Emails []ObjectId `json:"emails"`
22+
Previews *[]EmailResponsePreview `json:"previews"`
1623
}
1724

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

119+
if emailResponse.Previews != nil {
120+
for _, preview := range *emailResponse.Previews {
121+
log.Printf("Templateless [TEST MODE]: Emailed %s, preview: https://tmpl.sh/%s\n",
122+
preview.Email, preview.Preview)
123+
}
124+
}
125+
112126
return emailResponse.Emails, nil
113127
default:
114128
return nil, UnknownError()

0 commit comments

Comments
 (0)