https://github.com/paganotoni/sendgrid-sender
Buffalo's sender implementation for Sendgrid in Go
https://github.com/paganotoni/sendgrid-sender
email gobuffalo golang sender sendgrid
Last synced: about 1 year ago
JSON representation
Buffalo's sender implementation for Sendgrid in Go
- Host: GitHub
- URL: https://github.com/paganotoni/sendgrid-sender
- Owner: paganotoni
- Created: 2018-09-06T17:25:28.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2021-10-07T13:51:20.000Z (over 4 years ago)
- Last Synced: 2025-03-31T12:04:43.975Z (about 1 year ago)
- Topics: email, gobuffalo, golang, sender, sendgrid
- Language: Go
- Homepage:
- Size: 71.3 KB
- Stars: 10
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
### Sendgrid Buffalo Sender
This is a [buffalo](https://github.com/gobuffalo/buffalo) sender for the [Sendgrid](https://sendgrid.com) email service.
#### How to use
In your `mailers.go`
```go
import (
...
ssender "github.com/paganotoni/sendgrid-sender"
)
var sender mail.Sender
func init() {
APIKey := envy.Get("SENDGRID_API_KEY", "")
sender = ssender.NewSendgridSender(APIKey)
}
```
And then in your mailers you would do the same `sender.Send(m)` as this sender matches buffalos [`mail.Sender`](https://github.com/gobuffalo/buffalo/blob/master/mail/mail.go#L4) interface.
#### Add Custom Args
To add custom args, you must add values using `CustomArgs` type and add it into Message.Data ussing `CustomArgsKey` key
```go
CustomArgsKey = "sendgrid_custom_args_key"
...
type CustomArgs map[string]string
```
#### How to use Sendgrid customargs
One thing you could need is to add customArgs to the message you're sending through sendgrid, to do this you would be using `SetCustomArgs` function, passing your `mail.Message`with the `CustomArgs` you want to add.
```go
import (
...
ssender "github.com/paganotoni/sendgrid-sender"
)
func main() {
APIKey := envy.Get("SENDGRID_API_KEY", "")
sender = ssender.NewSendgridSender(APIKey)
m := mail.NewMessage()
...
ssender.SetCustomArgs(m, ssender.CustomArgs{
"custom_arg_0": "custom_value_0",
"custom_arg_1": "custom_value_1",
...
})
if err := sender.Send(m); err != nil{
...
}
}
```
#### Test mode
Whenever the GO_ENV variable is set to be `test` this sender will use [mocksmtp](https://github.com/stanislas-m/mocksmtp) sender to send messages, you can read values in your tests within the property `TestSender` of the SendgridSender.