Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ coverage-check:
.PHONY: update-examples
update-examples:
@echo "Updating example files..."
go run ./examples
go run ./examples/main.go
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Go-Mailgen

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

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

```bash
go get github.com/afkdevs/go-mailgen
go get github.com/akfaiz/go-mailgen
```

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

import (
"github.com/afkdevs/go-mailgen"
"github.com/akfaiz/go-mailgen"
"github.com/wneessen/go-mail"
)

Expand All @@ -55,7 +55,7 @@ func main() {
From("no-reply@example.com", "Go-Mailgen").
Product(mailgen.Product{
Name: "Go-Mailgen",
Link: "https://github.com/afkdevs/go-mailgen",
Link: "https://github.com/akfaiz/go-mailgen",
}).
Theme("default"),
)
Expand Down Expand Up @@ -91,7 +91,7 @@ You can find more examples in the [examples](examples) directory.

## Documentation

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

## Supported Themes

Expand Down
28 changes: 24 additions & 4 deletions builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"sync/atomic"
"time"

"github.com/afkdevs/go-mailgen/templates"
"github.com/akfaiz/go-mailgen/templates"
"github.com/vanng822/go-premailer/premailer"
)

Expand All @@ -26,6 +26,7 @@ type Product struct {
type Builder struct {
subject string
from Address
replyTo *Address
to []string
cc []string
bcc []string
Expand Down Expand Up @@ -56,15 +57,15 @@ func newDefaultBuilder() *Builder {
salutation: "Best regards",
product: Product{
Name: "Go-Mailgen",
Link: "https://github.com/afkdevs/go-mailgen",
Link: "https://github.com/akfaiz/go-mailgen",
Copyright: fmt.Sprintf("© %d Go-Mailgen. All rights reserved.", time.Now().Year()),
},
fallbackFormat: "If you're having trouble clicking the \"[ACTION]\" button, copy and paste the URL below into your web browser:",
}
}

func (b *Builder) clone() *Builder {
return &Builder{
new := &Builder{
textDirection: b.textDirection,
subject: b.subject,
from: b.from,
Expand All @@ -81,6 +82,11 @@ func (b *Builder) clone() *Builder {
components: append([]Component{}, b.components...),
product: b.product,
}
if b.replyTo != nil {
b.replyTo = &Address{Name: b.replyTo.Name, Address: b.replyTo.Address}
}

return new
}

// SetDefault sets the default Builder instance.
Expand All @@ -92,7 +98,7 @@ func (b *Builder) clone() *Builder {
// mailgen.SetDefault(mailgen.New().
// Product(mailgen.Product{
// Name: "Go-Mailgen",
// Link: "https://github.com/afkdevs/go-mailgen",
// Link: "https://github.com/akfaiz/go-mailgen",
// Logo: "https://upload.wikimedia.org/wikipedia/commons/0/05/Go_Logo_Blue.svg",
// }).
// Theme("default"))
Expand Down Expand Up @@ -136,6 +142,19 @@ func (b *Builder) From(address string, name ...string) *Builder {
return b
}

// ReplyTo sets the Reply-To email address for the email message.
// It can include a name for the Reply-To address.
func (b *Builder) ReplyTo(address string, name ...string) *Builder {
addr := Address{
Address: address,
}
if len(name) > 0 {
addr.Name = name[0]
}
b.replyTo = &addr
return b
}

// To add a recipient's email address to the email message.
func (b *Builder) To(to string, others ...string) *Builder {
values := b.filterRecipients(to, others...)
Expand Down Expand Up @@ -358,6 +377,7 @@ func (b *Builder) Build() (Message, error) {
return &message{
subject: b.subject,
from: b.from,
replyTo: b.replyTo,
to: b.to,
cc: b.cc,
bcc: b.bcc,
Expand Down
40 changes: 39 additions & 1 deletion builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"testing"
"time"

"github.com/afkdevs/go-mailgen"
"github.com/akfaiz/go-mailgen"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down Expand Up @@ -174,6 +174,44 @@ func TestBuilder_From(t *testing.T) {
}
}

func TestBuilder_ReplyTo(t *testing.T) {
testCases := []testCase{
{
name: "set reply-to",
builderFunc: func() *mailgen.Builder {
return mailgen.New().ReplyTo("replyto@example.com")
},
expectError: false,
expectFunc: func(msg mailgen.Message) {
assert.Equal(t, "replyto@example.com", msg.ReplyToString(), "Reply-To should match the set value")
},
},
{
name: "set reply-to with name",
builderFunc: func() *mailgen.Builder {
return mailgen.New().ReplyTo("replyto@example.com", "Reply To Name")
},
expectError: false,
expectFunc: func(msg mailgen.Message) {
assert.Equal(t, "Reply To Name <replyto@example.com>", msg.ReplyToString(), "Reply-To should match the set value")
},
},
{
name: "not set reply-to",
builderFunc: func() *mailgen.Builder {
return mailgen.New()
},
expectError: false,
expectFunc: func(msg mailgen.Message) {
assert.Equal(t, "", msg.ReplyToString(), "Reply-To should be empty")
},
},
}
for _, tc := range testCases {
tc.run(t)
}
}

func TestBuilder_To(t *testing.T) {
testCases := []testCase{
{
Expand Down
2 changes: 1 addition & 1 deletion component_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
htmltemplate "html/template"
"testing"

"github.com/afkdevs/go-mailgen"
"github.com/akfaiz/go-mailgen"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
Expand Down
2 changes: 1 addition & 1 deletion examples/default/receipt.html

Large diffs are not rendered by default.

6 changes: 1 addition & 5 deletions examples/default/receipt.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Go-Mailgen] (https://github.com/afkdevs/go-mailgen)
[Go-Mailgen] (https://github.com/akfaiz/go-mailgen)

************
Hi John Doe,
Expand All @@ -20,8 +20,4 @@ We thank you for your purchase.
Best regards,
Go-Mailgen

If you're having trouble clicking the "Go to Dashboard" button, copy and paste the URL below into your web browser:

https://example.com/dashboard

© 2025 Go-Mailgen. All rights reserved.
2 changes: 1 addition & 1 deletion examples/default/reset.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
:root {
color-scheme: light dark !important;
supported-color-schemes: light dark !important
}</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>
}</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>
6 changes: 1 addition & 5 deletions examples/default/reset.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[Go-Mailgen] (https://github.com/afkdevs/go-mailgen)
[Go-Mailgen] (https://github.com/akfaiz/go-mailgen)

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

If you're having trouble clicking the "Reset your password" button, copy and paste the URL below into your web browser:

https://example.com/reset-password

© 2025 Go-Mailgen. All rights reserved.
Loading