https://github.com/rhaqim/gomail
Golang package for sending template emails to end users. Provide SMTP credentials and the email templates.
https://github.com/rhaqim/gomail
email email-sender go-templates golang package smtp templates
Last synced: 4 months ago
JSON representation
Golang package for sending template emails to end users. Provide SMTP credentials and the email templates.
- Host: GitHub
- URL: https://github.com/rhaqim/gomail
- Owner: Rhaqim
- License: mit
- Created: 2024-04-17T09:19:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-04-27T03:22:20.000Z (about 1 year ago)
- Last Synced: 2025-01-11T01:55:26.545Z (5 months ago)
- Topics: email, email-sender, go-templates, golang, package, smtp, templates
- Language: Go
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Gomail
[](https://pkg.go.dev/github.com/Rhaqim/gomail)
[](https://goreportcard.com/report/github.com/Rhaqim/gomail)Gomail is a Golang module that provides an abstraction for sending template emails to users in Golang applications. It allows users to provide their SMTP credentials and a folder for the email templates, and then sends the email using the specified template.
## Installation
To install Gomail, use the following command:
```bash
go get github.com/rhaqim/gomail
```## Usage
To use Gomail, you need to import the module and create a new instance of the `Gomail` struct. You can then use the `SendEmail` method to send an email.
```go
package mainimport (
"log"
"github.com/rhaqim/gomail"
)func main() {
auth := gomail.EmailAuthConfig{
Host: "smtp.gmail.com",
Port: 587,
Username: "user",
Password: "password",
From: "[email protected]",
}templateDir := "templates"
g := gomail.NewGomail(auth, templatesDir)
App(g)
}
func App(mail gomail.Gomail) {
email := &gomail.Email{
Recipients: []string{"[email protected]", "[email protected]"},
Subject: "Hello",
Body: "Hello, this is a test email",
TemplateFileName: "hello.html",
Data: map[string]interface{}{"Title": "Hello", "Body": "Hello, this is a test email"},
}err := mail.SendEmail(email)
if err != nil {
log.Fatal(err)
}
}
```The template file should be in the specified template directory and should be an HTML file. The template file should contain the email body and any other information that you want to include in the email.
```html
My Go Template
{{.Title }}
{{ .Body }}
```## Contributing
To contribute to Gomail, fork the repository and create a new branch. Once you have made your changes, submit a pull request.