You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Go-Mailer is a Go library that wraps the [wneessen/go-mail](https://github.com/wneessen/go-mail) library to provide a simplified interface for sending emails using an existing `mail.Client` instance. This library enhances `go-mail` with a fluent HTML message builder, making it easy to create and send rich, dynamic email content.
10
+
**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.
10
11
11
12
## Features
12
-
-**Uses Existing `mail.Client`**: Integrates with an existing `wneessen/go-mail` client for flexible configuration and reuse.
13
-
-**Fluent HTML Message Builder**: Provides a chainable API for constructing HTML emails with methods like `Subject`, `To`, `Line`, `Action`, etc.
14
-
- Attachment Support: Easily attach files from local disk, embedded filesystems, IOFS filesystems, or `io.Reader`/`io.ReadSeeker`.
15
-
- Responsive HTML Template: Automatically formats emails with a clean, responsive design compatible with most email clients.
16
-
- CSS-inlined HTML: Automatically inlines CSS styles for better compatibility with email clients that strip out `<style>` tags.
13
+
14
+
-**Fluent API**: Build emails with a clean, chainable interface.
15
+
-**Inline CSS**: Ensures compatibility across major email clients.
16
+
-**Template-Based**: Use pre-built or custom templates for rapid development.
17
+
-**Easy Integration**: Works effortlessly with popular Go mail libraries like go-mail.
18
+
-**Dynamic Components Ordering**: Add components like buttons, tables, and lines in any order you want.
17
19
18
20
## Installation
19
-
To install Go-Mailer, run the following command:
21
+
22
+
To install Go-Mailgen, run the following command:
20
23
21
24
```bash
22
-
go get github.com/ahmadfaizk/go-mailer
25
+
go get github.com/ahmadfaizk/go-mailgen
23
26
```
24
27
25
-
This will also install the `wneessen/go-mail` dependency.
26
-
27
28
## Usage
28
-
Go-Mailer requires an existing `mail.Client` instance from `wneessen/go-mail` to send emails. Below is an example demonstrating how to initialize the mailer and send an HTML email using the fluent message builder:
29
+
30
+
Here's a simple example of how to use Go-Mailgen to create an email:
29
31
30
32
```go
31
33
package main
32
34
33
35
import (
34
-
"context"
35
-
"github.com/ahmadfaizk/go-mailer"
36
-
"github.com/wneessen/go-mail"
36
+
"github.com/ahmadfaizk/go-mailgen"
37
+
"github.com/wneessen/go-mail"
37
38
)
38
39
39
40
funcmain() {
40
-
// Create a new go-mail client
41
-
client, err:= mail.NewClient("smtp.example.com",
42
-
mail.WithPort(587),
43
-
mail.WithSMTPAuth(mail.SMTPAuthPlain),
44
-
mail.WithUsername("your-username"),
45
-
mail.WithPassword("your-password"),
46
-
)
47
-
if err != nil {
48
-
panic(err)
49
-
}
50
-
51
-
// Initialize the Go-Mailer instance with the existing client
52
-
m:= mailer.New(client,
53
-
mailer.WithFrom("noreply@example.com"),
54
-
mailer.WithProduct(mailer.Product{
55
-
Name: "My Application",
56
-
URL: "https://example.com",
57
-
})
58
-
)
59
-
60
-
// Build an HTML email using the fluent message builder
61
-
message:= mailer.NewMessage().
62
-
Subject("Reset Password").
63
-
To("recipient@example.com").
64
-
Line("Click the button below to reset your password").
0 commit comments