Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wisdommatt/mailit
An email kit for golang to be reused across different projects.
https://github.com/wisdommatt/mailit
golang golang-application golang-library golang-module golang-package golang-tools golang-wrapper
Last synced: 2 months ago
JSON representation
An email kit for golang to be reused across different projects.
- Host: GitHub
- URL: https://github.com/wisdommatt/mailit
- Owner: wisdommatt
- License: mit
- Created: 2021-01-04T10:56:03.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-12-02T15:55:54.000Z (about 3 years ago)
- Last Synced: 2024-06-20T19:19:12.893Z (6 months ago)
- Topics: golang, golang-application, golang-library, golang-module, golang-package, golang-tools, golang-wrapper
- Language: Go
- Homepage:
- Size: 26.4 KB
- Stars: 6
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Mailit
An email kit for golang to be reused across different projects.## Introduction
Mailit is an easy to use mail library to send emails.## Features
Mailit supports:
- Plain text emails
- Text / HTML template based emails
- Attachments
- Sending emails to multiple recipients## Requirements
> * Go 1.5## Documentation
https://pkg.go.dev/github.com/wisdommatt/mailit
***
We also recommend you use the how to guide on this page because Mailit does basically two things:* Send Plain Text Emails
* Send Template Based Emails## How To Use Mailit
###### Feel free to copy and paste the codes***
- #### Step 1: Initialize a mailer variable and pass in SMTP configs.
> #### Note: This is usually done just once```go
smtpConf := mailit.SMTPConfig{
Host: "domain.com",
Port: 563,
Username: "[email protected]",
Password: "*********",
}
mailer := mailit.NewMailer(smtpConf)
```- #### Step 2: Send email
> ##### Sending plain text email```go
textDep := mailit.TextDependencies{
From: "[email protected]",
To: []string{"[email protected]", "[email protected]", "[email protected]"},
Subject: "Welcome to Mailit",
Body: "Message Body",
Attachments: []string{"attachments/1.txt", "attachments/2.txt"},
}
err := mailer.SendText(textDep)
```
***> ##### Sending HTML template email
```go
tempDep := mailit.TemplateDependencies{
From: "[email protected]",
To: []string{"[email protected]", "[email protected]", "[email protected]"},
Subject: "Welcome to Mailit",
ContentType: "text/html",
Template: "templates/welcome.html",
TemplateData: "Any data",
Attachments: []string{"attachments/1.txt", "attachments/2.txt"},
}
err := mailer.SendTemplate(tempDep)
```***
> ##### Sending Text template email
```go
tempDep := mailit.TemplateDependencies{
From: "[email protected]",
To: []string{"[email protected]", "[email protected]", "[email protected]"},
Subject: "Welcome to Mailit",
ContentType: "text/plain",
Template: "templates/sample.txt",
TemplateData: struct{
Name, Email string
}{
Name: "Wisdom Matt",
Email: "[email protected]",
},
Attachments: []string{"attachments/1.txt", "attachments/2.txt"},
}
err := mailer.SendTemplate(tempDep)
```
***
> NOTE: You will access the template data the way it is access usually in Go templates e.g {{ .Name }} or {{ .Email }}
***
## Dependencies- https://github.com/go-gomail/gomail
## Testing
This package uses manual testing because the gomail package which it depends on used core types instead of interfaces which in turn makes it difficult to test, a thorough test is done before any changed is made on the project so there is nothing to be scared of.
## License
[MIT](LICENSE)
## Author / Contact
[Wisdom Matthew](https://wisdommatt.github.io/) - github.com/wisdommatt
Feel free to email me at [email protected]