Skip to content

Commit dc01aaf

Browse files
authored
feat: update screenshots and some documentation (#9)
1 parent 9f44195 commit dc01aaf

File tree

19 files changed

+82
-35
lines changed

19 files changed

+82
-35
lines changed

README.md

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
[![Go Version](https://img.shields.io/github/go-mod/go-version/ahmadfaizk/go-mailgen)](https://golang.org/doc/devel/release.html)
88
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
99

10+
<div align="center"><img src="./logo.png" width="150" alt="go-mailgen logo"/></div>
11+
1012
**Go-Mailgen** is a Go library for generating professional HTML emails using a fluent, intuitive API. Simplify email creation with customizable templates and seamless integration into your Go applications. This project is inspired by the [mailgen](https://github.com/eladnava/mailgen) Node.js package, bringing its elegant email generation approach to the Go ecosystem.
1113

1214
## Features
1315

1416
- **Fluent API**: Build emails with a clean, chainable interface.
1517
- **Inline CSS**: Ensures compatibility across major email clients.
16-
- **Template-Based**: Use pre-built or custom templates for rapid development.
1718
- **Easy Integration**: Works effortlessly with popular Go mail libraries like go-mail.
1819
- **Chainable Methods**: Add content, actions, and tables in a straightforward manner.
19-
- **Global Configuration**: Set default sender, product information, and theme for all emails.
20+
- **Global Configuration**: Set default base email settings and themes.
2021

2122
## Installation
2223

@@ -54,7 +55,7 @@ func main() {
5455
From("no-reply@example.com", "Go-Mailgen").
5556
Product(mailgen.Product{
5657
Name: "Go-Mailgen",
57-
URL: "https://github.com/ahmadfaizk/go-mailgen",
58+
Link: "https://github.com/ahmadfaizk/go-mailgen",
5859
}).
5960
Theme("default"),
6061
)
@@ -89,6 +90,7 @@ func main() {
8990
You can find more examples in the [examples](examples) directory.
9091

9192
## Documentation
93+
9294
For detailed documentation, please visit the [Go-Mailgen documentation](https://pkg.go.dev/github.com/ahmadfaizk/go-mailgen).
9395

9496
## Supported Themes
@@ -97,11 +99,31 @@ The following open-source themes are bundled with this package:
9799

98100
- `default` by [Postmark Transactional Email Templates](https://github.com/ActiveCampaign/postmark-templates)
99101

100-
<img src="examples/default/welcome.png" height="200" /> <img src="examples/default/reset.png" height="200" /> <img src="examples/default/receipt.png" height="200" />
102+
| Welcome | Reset Password | Receipt |
103+
|---------|----------------|---------|
104+
| <img src="examples/default/welcome.png" height="200" /> | <img src="examples/default/reset.png" height="200" /> | <img src="examples/default/receipt.png" height="200" /> |
101105

102106
- `plain` by [Postmark Transactional Email Templates](https://github.com/ActiveCampaign/postmark-templates)
103107

104-
<img src="examples/plain/welcome.png" height="200" /> <img src="examples/plain/reset.png" height="200" /> <img src="examples/plain/receipt.png" height="200" />
108+
| Welcome | Reset Password | Receipt |
109+
|---------|----------------|---------|
110+
| <img src="examples/plain/welcome.png" height="200" /> | <img src="examples/plain/reset.png" height="200" /> | <img src="examples/plain/receipt.png" height="200" /> |
111+
112+
## RTL Support
113+
114+
To change default text direction to RTL, you can use the `TextDirection` method:
115+
116+
```go
117+
// Set the text direction when creating a new email
118+
email := mailgen.New().
119+
TextDirection("rtl").
120+
Line("هذا هو عنوان البريد الإلكتروني الخاص بك")
121+
// or set it globally
122+
mailgen.SetDefault(mailgen.New().TextDirection("rtl"))
123+
// Then build the email as usual
124+
email := mailgen.New().
125+
Line("هذا هو عنوان البريد الإلكتروني الخاص بك")
126+
```
105127

106128
## Elements
107129

@@ -112,15 +134,12 @@ Go-Mailgen provides several methods to add content to your emails. Here are some
112134
To add an action button to your email, use the `Action` method:
113135

114136
```go
115-
mailgen.New().
137+
email := mailgen.New().
116138
Line("To confirm your email address, please click the button below:").
117139
Action("Confirm Email", "https://example.com/confirm")
118-
```
119140

120-
To add multiple actions to your email, you can chain the `Action` method:
121-
122-
```go
123-
mailgen.New().
141+
// To add multiple actions, you can chain the `Action` method:
142+
email := mailgen.New().
124143
Line("To confirm your email address, please click the buttons below:").
125144
Action("Confirm Email", "https://example.com/confirm").
126145
Line("Or you can visit our website:").
@@ -132,7 +151,7 @@ mailgen.New().
132151
To add a table to your email, use the `Table` method:
133152

134153
```go
135-
mailgen.New().
154+
email := mailgen.New().
136155
Line("Your order has been processed successfully.").
137156
Table(mailgen.Table{
138157
Data: [][]mailgen.Entry{
@@ -162,7 +181,7 @@ mailgen.New().
162181
You can chain the `Table` with other methods to add more content to your email:
163182

164183
```go
165-
mailgen.New().
184+
email := mailgen.New().
166185
Line("Your order has been processed successfully.").
167186
Table(mailgen.Table{
168187
Data: [][]mailgen.Entry{

builder.go

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,16 @@ func (b *Builder) clone() *Builder {
121121
// SetDefault sets the default Builder instance.
122122
//
123123
// It can be useful for set global defaults or configurations for the email messages.
124+
//
125+
// Example usage:
126+
//
127+
// mailgen.SetDefault(mailgen.New().
128+
// Product(mailgen.Product{
129+
// Name: "Go-Mailgen",
130+
// Link: "https://github.com/ahmadfaizk/go-mailgen",
131+
// Logo: "https://upload.wikimedia.org/wikipedia/commons/0/05/Go_Logo_Blue.svg",
132+
// }).
133+
// Theme("default"))
124134
func SetDefault(b *Builder) {
125135
if b == nil {
126136
return
@@ -132,7 +142,7 @@ func SetDefault(b *Builder) {
132142
//
133143
// Example usage:
134144
//
135-
// message := mailer.NewMessage().
145+
// message := mailgen.New().
136146
// Subject("Reset Password").
137147
// To("recipient@example.com").
138148
// Line("Click the button below to reset your password").
@@ -229,7 +239,8 @@ func (b *Builder) TextDirection(direction string) *Builder {
229239
//
230240
// Example usage:
231241
//
232-
// message.FallbackFormat("If you're having trouble clicking the \"[ACTION]\" button, copy and paste the URL below into your web browser:")
242+
// email := mailgen.New().
243+
// FallbackFormat("If you're having trouble clicking the \"[ACTION]\" button, copy and paste the URL below into your web browser:")
233244
func (b *Builder) FallbackFormat(format string) *Builder {
234245
if format == "" {
235246
return b // No format provided, do nothing
@@ -285,9 +296,14 @@ func (b *Builder) Linef(format string, args ...interface{}) *Builder {
285296
return b.Line(text)
286297
}
287298

288-
// Action sets the action text and URL for the email message.
289-
// It creates a button in the email that links to the specified URL.
290-
// The action can also include an optional instruction and color for the button.
299+
// Action sets the action text and link for the email message.
300+
// It creates a button that the recipient can click to perform an action.
301+
//
302+
// Example usage:
303+
//
304+
// email := mailgen.New().
305+
// Line("Click the button below to get started").
306+
// Action("Get Started", "https://example.com/get-started")
291307
func (b *Builder) Action(text, link string, cfg ...Action) *Builder {
292308
action := &component.Action{
293309
Text: text,
@@ -331,8 +347,9 @@ func (b *Builder) Product(product Product) *Builder {
331347
//
332348
// Example usage:
333349
//
334-
// message.Table(mailer.Table{
335-
// Data: [][]mailer.Entry{
350+
// email := mailgen.New().
351+
// Table(mailgen.Table{
352+
// Data: [][]mailgen.Entry{
336353
// {
337354
// {Key: "Name", Value: "John Doe"},
338355
// {Key: "Email", Value: "john.doe@example.com"},
@@ -342,7 +359,7 @@ func (b *Builder) Product(product Product) *Builder {
342359
// {Key: "Email", Value: "jane.smith@example.com"},
343360
// },
344361
// },
345-
// Columns: mailer.Columns{
362+
// Columns: mailgen.Columns{
346363
// CustomWidth: map[string]string{
347364
// "Name": "50%",
348365
// "Email": "50%",
@@ -363,7 +380,9 @@ func (b *Builder) Table(table Table) *Builder {
363380
}
364381

365382
// Build generates the final Message object with the HTML and plaintext content.
383+
//
366384
// It processes all the components, actions, and other fields set in the Builder.
385+
//
367386
// Returns an error if there is an issue generating the HTML or plaintext content.
368387
func (b *Builder) Build() (Message, error) {
369388
b.beforeBuild()

examples/default/receipt.png

-5.03 KB
Loading

examples/default/receipt.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Go-Mailgen] ( https://github.com/ahmadfaizk/go-mailgen )
1+
[Go-Mailgen] (https://github.com/ahmadfaizk/go-mailgen)
22

33
************
44
Hi John Doe,
@@ -13,7 +13,7 @@ Mailgen | Programmatically create beautiful e-mails using Golang | $1.99
1313

1414
You can check the status of your order and more in your dashboard:
1515

16-
Go to Dashboard ( https://example.com/dashboard )
16+
Go to Dashboard (https://example.com/dashboard)
1717

1818
We thank you for your purchase.
1919

examples/default/reset.png

-4.65 KB
Loading

examples/default/reset.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Go-Mailgen] ( https://github.com/ahmadfaizk/go-mailgen )
1+
[Go-Mailgen] (https://github.com/ahmadfaizk/go-mailgen)
22

33
************
44
Hi John Doe,
@@ -8,7 +8,7 @@ You have received this email because a password reset request for your account w
88

99
Click the button below to reset your password:
1010

11-
Reset your password ( https://example.com/reset-password )
11+
Reset your password (https://example.com/reset-password)
1212

1313
If you did not request a password reset, no further action is required on your part.
1414

examples/default/welcome.png

-4.97 KB
Loading

examples/default/welcome.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Go-Mailgen] ( https://github.com/ahmadfaizk/go-mailgen )
1+
[Go-Mailgen] (https://github.com/ahmadfaizk/go-mailgen)
22

33
************
44
Hi John Doe,
@@ -8,7 +8,7 @@ Welcome to Go-Mailgen! We're very excited to have you on board.
88

99
To get started with Mailgen, please click here:
1010

11-
Get Started ( https://example.com/get-started )
11+
Get Started (https://example.com/get-started)
1212

1313
We're glad to have you on board.
1414

examples/plain/receipt.png

5.01 KB
Loading

examples/plain/receipt.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[Go-Mailgen] ( https://github.com/ahmadfaizk/go-mailgen )
1+
[Go-Mailgen] (https://github.com/ahmadfaizk/go-mailgen)
22

33
************
44
Hi John Doe,
@@ -13,7 +13,7 @@ Mailgen | Programmatically create beautiful e-mails using Golang | $1.99
1313

1414
You can check the status of your order and more in your dashboard:
1515

16-
Go to Dashboard ( https://example.com/dashboard )
16+
Go to Dashboard (https://example.com/dashboard)
1717

1818
We thank you for your purchase.
1919

0 commit comments

Comments
 (0)