https://github.com/core-go/mail
https://github.com/core-go/mail
email mail send-grid sendgrid smtp
Last synced: 4 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/core-go/mail
- Owner: core-go
- Created: 2020-06-27T10:53:08.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2022-08-07T18:49:51.000Z (almost 3 years ago)
- Last Synced: 2025-01-10T04:15:09.926Z (6 months ago)
- Topics: email, mail, send-grid, sendgrid, smtp
- Language: Go
- Homepage:
- Size: 25.4 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README

- The sample is [go-authentication](https://github.com/project-samples/go-authentication)## Model
## Service
- MailService## Implementations
There are 2 implementations of MailService:
- SMTP
- SendGrid## Installation
Please make sure to initialize a Go module before installing core-go/mail:```shell
go get -u github.com/core-go/mail
```Import:
```go
import "github.com/core-go/mail"
```## Details
#### mail_service.go
```go
type MailService interface {
Send(mail Mail) error
}
```## Example of SMTP
```go
package mainimport (
"github.com/core-go/mail"
"github.com/core-go/mail/smtp"
)func main() {
// Create a new smtp mail service
config := smtp.DialerConfig{"smtp.gmail.com", 587, "[email protected]", "test", true}
mailService := smtp.NewSmtpMailSender(config)subject := "Your smtp demo"
content := `Content of the email`mailFrom := mail.Email{Address: "[email protected]"}
mailTo := []mail.Email{{Address: "[email protected]"}}
mailData := mail.NewHtmlMail(mailFrom, subject, mailTo, nil, content)mailService.Send(*mailData)
}
```## Example of SendGrid
```go
package mainimport (
"github.com/core-go/mail"
"github.com/core-go/mail/sendgrid"
)func main() {
// Create a new sendgrid mail service
mailService := sendgrid.NewSendGridMailSender("xx.xxxxOQVcRKGxxxxk2KJc4g.fM7m9NIxxxxSLNOzxxxxfxF9bH4mnRrIysJA8q-xxxx")subject := "Your sendgrid demo"
content := `Content of the email`mailFrom := mail.Email{Address: "[email protected]"}
mailTo := []mail.Email{{Address: "[email protected]"}}
mailData := mail.NewHtmlMail(mailFrom, subject, mailTo, nil, content)mailService.Send(*mailData)
}
```