An open API service indexing awesome lists of open source software.

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.

Awesome Lists containing this project

README

        

# Gomail

[![Go Reference](https://pkg.go.dev/badge/github.com/Rhaqim/gomail.svg)](https://pkg.go.dev/github.com/Rhaqim/gomail)
[![Go Report Card](https://goreportcard.com/badge/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 main

import (
"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.