Skip to content

Commit 250303a

Browse files
authored
Feat/change package name (#11)
* feat: change package name * feat: add set reply-to * fix: failed unit test
1 parent 138b5b2 commit 250303a

27 files changed

+173
-126
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ coverage-check:
4949
.PHONY: update-examples
5050
update-examples:
5151
@echo "Updating example files..."
52-
go run ./examples
52+
go run ./examples/main.go

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
# Go-Mailgen
22

3-
[![Go](https://github.com/afkdevs/go-mailgen/actions/workflows/ci.yml/badge.svg)](https://github.com/afkdevs/go-mailgen/actions/workflows/ci.yml)
4-
[![Go Report Card](https://goreportcard.com/badge/github.com/afkdevs/go-mailgen)](https://goreportcard.com/report/github.com/afkdevs/go-mailgen)
5-
[![codecov](https://codecov.io/gh/afkdevs/go-mailgen/graph/badge.svg?token=7tbSVRaD4b)](https://codecov.io/gh/afkdevs/go-mailgen)
6-
[![GoDoc](https://pkg.go.dev/badge/github.com/afkdevs/go-mailgen)](https://pkg.go.dev/github.com/afkdevs/go-mailgen)
7-
[![Go Version](https://img.shields.io/github/go-mod/go-version/afkdevs/go-mailgen)](https://golang.org/doc/devel/release.html)
3+
[![Go](https://github.com/akfaiz/go-mailgen/actions/workflows/ci.yml/badge.svg)](https://github.com/akfaiz/go-mailgen/actions/workflows/ci.yml)
4+
[![Go Report Card](https://goreportcard.com/badge/github.com/akfaiz/go-mailgen)](https://goreportcard.com/report/github.com/akfaiz/go-mailgen)
5+
[![codecov](https://codecov.io/gh/akfaiz/go-mailgen/graph/badge.svg?token=7tbSVRaD4b)](https://codecov.io/gh/akfaiz/go-mailgen)
6+
[![GoDoc](https://pkg.go.dev/badge/github.com/akfaiz/go-mailgen)](https://pkg.go.dev/github.com/akfaiz/go-mailgen)
7+
[![Go Version](https://img.shields.io/github/go-mod/go-version/akfaiz/go-mailgen)](https://golang.org/doc/devel/release.html)
88
[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)
99

1010
<div align="center"><img src="./logo.png" width="150" alt="go-mailgen logo"/></div>
@@ -24,7 +24,7 @@
2424
To install Go-Mailgen, run the following command:
2525

2626
```bash
27-
go get github.com/afkdevs/go-mailgen
27+
go get github.com/akfaiz/go-mailgen
2828
```
2929

3030
## Usage
@@ -35,7 +35,7 @@ Here's a simple example of how to use Go-Mailgen to create an email:
3535
package main
3636

3737
import (
38-
"github.com/afkdevs/go-mailgen"
38+
"github.com/akfaiz/go-mailgen"
3939
"github.com/wneessen/go-mail"
4040
)
4141

@@ -55,7 +55,7 @@ func main() {
5555
From("no-reply@example.com", "Go-Mailgen").
5656
Product(mailgen.Product{
5757
Name: "Go-Mailgen",
58-
Link: "https://github.com/afkdevs/go-mailgen",
58+
Link: "https://github.com/akfaiz/go-mailgen",
5959
}).
6060
Theme("default"),
6161
)
@@ -91,7 +91,7 @@ You can find more examples in the [examples](examples) directory.
9191

9292
## Documentation
9393

94-
For detailed documentation, please visit the [Go-Mailgen documentation](https://pkg.go.dev/github.com/afkdevs/go-mailgen).
94+
For detailed documentation, please visit the [Go-Mailgen documentation](https://pkg.go.dev/github.com/akfaiz/go-mailgen).
9595

9696
## Supported Themes
9797

builder.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"sync/atomic"
1010
"time"
1111

12-
"github.com/afkdevs/go-mailgen/templates"
12+
"github.com/akfaiz/go-mailgen/templates"
1313
"github.com/vanng822/go-premailer/premailer"
1414
)
1515

@@ -26,6 +26,7 @@ type Product struct {
2626
type Builder struct {
2727
subject string
2828
from Address
29+
replyTo *Address
2930
to []string
3031
cc []string
3132
bcc []string
@@ -56,15 +57,15 @@ func newDefaultBuilder() *Builder {
5657
salutation: "Best regards",
5758
product: Product{
5859
Name: "Go-Mailgen",
59-
Link: "https://github.com/afkdevs/go-mailgen",
60+
Link: "https://github.com/akfaiz/go-mailgen",
6061
Copyright: fmt.Sprintf("© %d Go-Mailgen. All rights reserved.", time.Now().Year()),
6162
},
6263
fallbackFormat: "If you're having trouble clicking the \"[ACTION]\" button, copy and paste the URL below into your web browser:",
6364
}
6465
}
6566

6667
func (b *Builder) clone() *Builder {
67-
return &Builder{
68+
new := &Builder{
6869
textDirection: b.textDirection,
6970
subject: b.subject,
7071
from: b.from,
@@ -81,6 +82,11 @@ func (b *Builder) clone() *Builder {
8182
components: append([]Component{}, b.components...),
8283
product: b.product,
8384
}
85+
if b.replyTo != nil {
86+
b.replyTo = &Address{Name: b.replyTo.Name, Address: b.replyTo.Address}
87+
}
88+
89+
return new
8490
}
8591

8692
// SetDefault sets the default Builder instance.
@@ -92,7 +98,7 @@ func (b *Builder) clone() *Builder {
9298
// mailgen.SetDefault(mailgen.New().
9399
// Product(mailgen.Product{
94100
// Name: "Go-Mailgen",
95-
// Link: "https://github.com/afkdevs/go-mailgen",
101+
// Link: "https://github.com/akfaiz/go-mailgen",
96102
// Logo: "https://upload.wikimedia.org/wikipedia/commons/0/05/Go_Logo_Blue.svg",
97103
// }).
98104
// Theme("default"))
@@ -136,6 +142,19 @@ func (b *Builder) From(address string, name ...string) *Builder {
136142
return b
137143
}
138144

145+
// ReplyTo sets the Reply-To email address for the email message.
146+
// It can include a name for the Reply-To address.
147+
func (b *Builder) ReplyTo(address string, name ...string) *Builder {
148+
addr := Address{
149+
Address: address,
150+
}
151+
if len(name) > 0 {
152+
addr.Name = name[0]
153+
}
154+
b.replyTo = &addr
155+
return b
156+
}
157+
139158
// To add a recipient's email address to the email message.
140159
func (b *Builder) To(to string, others ...string) *Builder {
141160
values := b.filterRecipients(to, others...)
@@ -358,6 +377,7 @@ func (b *Builder) Build() (Message, error) {
358377
return &message{
359378
subject: b.subject,
360379
from: b.from,
380+
replyTo: b.replyTo,
361381
to: b.to,
362382
cc: b.cc,
363383
bcc: b.bcc,

builder_test.go

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/afkdevs/go-mailgen"
8+
"github.com/akfaiz/go-mailgen"
99
"github.com/stretchr/testify/assert"
1010
"github.com/stretchr/testify/require"
1111
)
@@ -174,6 +174,44 @@ func TestBuilder_From(t *testing.T) {
174174
}
175175
}
176176

177+
func TestBuilder_ReplyTo(t *testing.T) {
178+
testCases := []testCase{
179+
{
180+
name: "set reply-to",
181+
builderFunc: func() *mailgen.Builder {
182+
return mailgen.New().ReplyTo("replyto@example.com")
183+
},
184+
expectError: false,
185+
expectFunc: func(msg mailgen.Message) {
186+
assert.Equal(t, "replyto@example.com", msg.ReplyToString(), "Reply-To should match the set value")
187+
},
188+
},
189+
{
190+
name: "set reply-to with name",
191+
builderFunc: func() *mailgen.Builder {
192+
return mailgen.New().ReplyTo("replyto@example.com", "Reply To Name")
193+
},
194+
expectError: false,
195+
expectFunc: func(msg mailgen.Message) {
196+
assert.Equal(t, "Reply To Name <replyto@example.com>", msg.ReplyToString(), "Reply-To should match the set value")
197+
},
198+
},
199+
{
200+
name: "not set reply-to",
201+
builderFunc: func() *mailgen.Builder {
202+
return mailgen.New()
203+
},
204+
expectError: false,
205+
expectFunc: func(msg mailgen.Message) {
206+
assert.Equal(t, "", msg.ReplyToString(), "Reply-To should be empty")
207+
},
208+
},
209+
}
210+
for _, tc := range testCases {
211+
tc.run(t)
212+
}
213+
}
214+
177215
func TestBuilder_To(t *testing.T) {
178216
testCases := []testCase{
179217
{

component_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
htmltemplate "html/template"
55
"testing"
66

7-
"github.com/afkdevs/go-mailgen"
7+
"github.com/akfaiz/go-mailgen"
88
"github.com/stretchr/testify/assert"
99
"github.com/stretchr/testify/require"
1010
)

examples/default/receipt.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

examples/default/receipt.txt

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

33
************
44
Hi John Doe,
@@ -20,8 +20,4 @@ We thank you for your purchase.
2020
Best regards,
2121
Go-Mailgen
2222

23-
If you're having trouble clicking the "Go to Dashboard" button, copy and paste the URL below into your web browser:
24-
25-
https://example.com/dashboard
26-
2723
© 2025 Go-Mailgen. All rights reserved.

examples/default/reset.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,4 @@
4444
:root {
4545
color-scheme: light dark !important;
4646
supported-color-schemes: light dark !important
47-
}</style></head><body dir="ltr" style="height:100%;margin:0;-webkit-text-size-adjust:none;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;background-color:#F2F4F6;color:#51545E;width:100%"><table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;margin:0;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0;background-color:#F2F4F6"><tbody><tr><td align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><table class="email-content" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;margin:0;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0"><tbody><tr><td class="email-masthead" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;padding:25px 0;text-align:center"><a href="https://github.com/afkdevs/go-mailgen" class="f-fallback email-masthead_name" style="font-size:16px;font-weight:bold;color:#A8AAAF;text-decoration:none;text-shadow:0 1px 0 white"><img src="https://upload.wikimedia.org/wikipedia/commons/0/05/Go_Logo_Blue.svg" class="email-masthead_logo" alt="Go-Mailgen Logo" style="max-width:400px;border:0;max-height:50px"/></a></td></tr><tr><td class="email-body" width="570" cellpadding="0" cellspacing="0" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;width:100%;margin:0;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0"><table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation" style="width:570px;margin:0 auto;padding:0;-premailer-width:570px;-premailer-cellpadding:0;-premailer-cellspacing:0;background-color:#FFFFFF"><tbody><tr><td class="content-cell" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;padding:45px"><div class="f-fallback"><h1 style="margin-top:0;color:#333333;font-size:22px;font-weight:bold;text-align:left">Hi John Doe,</h1><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">You have received this email because a password reset request for your account was received.</p><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">Click the button below to reset your password:</p><table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;margin:30px auto;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0;text-align:center"><tbody><tr><td align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody><tr><td align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><a href="https://example.com/reset-password" class="f-fallback button" style="border-top:10px solid;border-right:18px solid;border-bottom:10px solid;border-left:18px solid;display:inline-block;color:#FFF;text-decoration:none;border-radius:3px;box-shadow:0 2px 3px rgba(0, 0, 0, 0.16);-webkit-text-size-adjust:none;box-sizing:border-box;background-color:#3869D4;border-color:#3869D4" target="_blank">Reset your password</a></td></tr></tbody></table></td></tr></tbody></table><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">If you did not request a password reset, no further action is required on your part.</p><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">Best regards,<br/>Go-Mailgen</p><table class="body-sub" role="presentation" style="margin-top:25px;padding-top:25px;border-top:1px solid #EAEAEC"><tbody><tr><td style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><p class="f-fallback sub" style="margin:.4em 0 1.1875em;line-height:1.625;color:#51545E;font-size:13px">If you&#39;re having trouble clicking the &#34;Reset your password&#34; button, copy and paste the URL below into your web browser:</p><p class="f-fallback sub" style="margin:.4em 0 1.1875em;line-height:1.625;color:#51545E;font-size:13px">https://example.com/reset-password</p></td></tr></tbody></table></div></td></tr></tbody></table></td></tr><tr><td style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation" style="width:570px;margin:0 auto;padding:0;-premailer-width:570px;-premailer-cellpadding:0;-premailer-cellspacing:0;text-align:center"><tbody><tr><td class="content-cell" align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;padding:45px"><p class="f-fallback sub align-center" style="margin:.4em 0 1.1875em;line-height:1.625;text-align:center;font-size:13px;color:#A8AAAF">© 2025 Go-Mailgen. All rights reserved.</p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></body></html>
47+
}</style></head><body dir="ltr" style="height:100%;margin:0;-webkit-text-size-adjust:none;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;background-color:#F2F4F6;color:#51545E;width:100%"><table class="email-wrapper" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;margin:0;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0;background-color:#F2F4F6"><tbody><tr><td align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><table class="email-content" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;margin:0;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0"><tbody><tr><td class="email-masthead" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;padding:25px 0;text-align:center"><a href="https://github.com/akfaiz/go-mailgen" class="f-fallback email-masthead_name" style="font-size:16px;font-weight:bold;color:#A8AAAF;text-decoration:none;text-shadow:0 1px 0 white"><img src="https://upload.wikimedia.org/wikipedia/commons/0/05/Go_Logo_Blue.svg" class="email-masthead_logo" alt="Go-Mailgen Logo" style="max-width:400px;border:0;max-height:50px"/></a></td></tr><tr><td class="email-body" width="570" cellpadding="0" cellspacing="0" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;width:100%;margin:0;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0"><table class="email-body_inner" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation" style="width:570px;margin:0 auto;padding:0;-premailer-width:570px;-premailer-cellpadding:0;-premailer-cellspacing:0;background-color:#FFFFFF"><tbody><tr><td class="content-cell" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;padding:45px"><div class="f-fallback"><h1 style="margin-top:0;color:#333333;font-size:22px;font-weight:bold;text-align:left">Hi John Doe,</h1><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">You have received this email because a password reset request for your account was received.</p><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">Click the button below to reset your password:</p><table class="body-action" align="center" width="100%" cellpadding="0" cellspacing="0" role="presentation" style="width:100%;margin:30px auto;padding:0;-premailer-width:100%;-premailer-cellpadding:0;-premailer-cellspacing:0;text-align:center"><tbody><tr><td align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><table width="100%" border="0" cellspacing="0" cellpadding="0" role="presentation"><tbody><tr><td align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><a href="https://example.com/reset-password" class="f-fallback button" style="border-top:10px solid;border-right:18px solid;border-bottom:10px solid;border-left:18px solid;display:inline-block;color:#FFF;text-decoration:none;border-radius:3px;box-shadow:0 2px 3px rgba(0, 0, 0, 0.16);-webkit-text-size-adjust:none;box-sizing:border-box;background-color:#3869D4;border-color:#3869D4" target="_blank">Reset your password</a></td></tr></tbody></table></td></tr></tbody></table><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">If you did not request a password reset, no further action is required on your part.</p><p style="margin:.4em 0 1.1875em;font-size:16px;line-height:1.625;color:#51545E">Best regards,<br/>Go-Mailgen</p><table class="body-sub" role="presentation" style="margin-top:25px;padding-top:25px;border-top:1px solid #EAEAEC"><tbody><tr><td style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><p class="f-fallback sub" style="margin:.4em 0 1.1875em;line-height:1.625;color:#51545E;font-size:13px">If you&#39;re having trouble clicking the &#34;Reset your password&#34; button, copy and paste the URL below into your web browser:</p><p class="f-fallback sub" style="margin:.4em 0 1.1875em;line-height:1.625;color:#51545E;font-size:13px">https://example.com/reset-password</p></td></tr></tbody></table></div></td></tr></tbody></table></td></tr><tr><td style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px"><table class="email-footer" align="center" width="570" cellpadding="0" cellspacing="0" role="presentation" style="width:570px;margin:0 auto;padding:0;-premailer-width:570px;-premailer-cellpadding:0;-premailer-cellspacing:0;text-align:center"><tbody><tr><td class="content-cell" align="center" style="word-break:break-word;font-family:&#34;Nunito Sans&#34;, Helvetica, Arial, sans-serif;font-size:16px;padding:45px"><p class="f-fallback sub align-center" style="margin:.4em 0 1.1875em;line-height:1.625;text-align:center;font-size:13px;color:#A8AAAF">© 2025 Go-Mailgen. All rights reserved.</p></td></tr></tbody></table></td></tr></tbody></table></td></tr></tbody></table></body></html>

examples/default/reset.txt

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

33
************
44
Hi John Doe,
@@ -15,8 +15,4 @@ If you did not request a password reset, no further action is required on your p
1515
Best regards,
1616
Go-Mailgen
1717

18-
If you're having trouble clicking the "Reset your password" button, copy and paste the URL below into your web browser:
19-
20-
https://example.com/reset-password
21-
2218
© 2025 Go-Mailgen. All rights reserved.

0 commit comments

Comments
 (0)