https://github.com/mattevans/postmark-go
✉️ Golang bindings for the Postmark API
https://github.com/mattevans/postmark-go
email go golang golang-library postmark postmark-api
Last synced: 5 months ago
JSON representation
✉️ Golang bindings for the Postmark API
- Host: GitHub
- URL: https://github.com/mattevans/postmark-go
- Owner: mattevans
- License: mit
- Created: 2016-09-22T02:30:24.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-21T09:15:25.000Z (over 2 years ago)
- Last Synced: 2024-06-19T00:26:44.368Z (almost 2 years ago)
- Topics: email, go, golang, golang-library, postmark, postmark-api
- Language: Go
- Homepage: http://developer.postmarkapp.com/
- Size: 57.6 KB
- Stars: 18
- Watchers: 4
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# postmark-go
[](https://godoc.org/github.com/mattevans/postmark-go)
[](https://travis-ci.org/mattevans/postmark-go)
[](https://github.com/mattevans/postmark-go/blob/master/LICENSE)
postmark-go is a [Go](http://golang.org) client library for accessing the Postmark API (http://developer.postmarkapp.com/).
This is an unofficial library that is not affiliated with [Postmark](http://postmarkapp.com). Official libraries are available
[here](http://developer.postmarkapp.com/developer-official-libs.html).
v1.0 Breaking Changes
---------------------
The signature of `NewClient` has changed. It now accepts options, one of which can be a custom HTTP client. Please pin to an older version if required.
Installation
-----------------
`go get -u github.com/mattevans/postmark-go`
Setup
-----------------
You'll need to pass an `SERVER_API_TOKEN` when initializing the client. This token can be
found under the 'Credentials' tab of your Postmark server. More info [here](http://developer.postmarkapp.com/developer-api-overview.html#authentication).
Client + Authentication
-----------------------
```go
client := postmark.NewClient(
postmark.WithClient(&http.Client{
Transport: &postmark.AuthTransport{Token: "SERVER_API_TOKEN"},
}),
)
```
Example usage (with Template)
-------------
```go
emailReq := &postmark.Email{
From: "mail@company.com",
To: "jack@sparrow.com",
TemplateID: 123456,
TemplateModel: map[string]interface{}{
"name": "Jack",
"action_url": "http://click.company.com/welcome",
},
Tag: "onboarding",
TrackOpens: true,
Metadata: map[string]string{
"client-id": "123456",
"client-ip": "127.0.0.1",
},
}
email, response, err := client.Email.Send(emailReq)
if err != nil {
return err
}
```
Example usage (with HtmlBody)
-------------
```go
emailReq := &postmark.Email{
From: "mail@company.com",
To: "jack@sparrow.com",
Subject: "My Test Email",
HtmlBody: "Hello dear Postmark user.",
TextBody: "Hello dear Postmark user",
Tag: "onboarding",
TrackOpens: true,
Metadata: map[string]string{
"client-id": "123456",
"client-ip": "127.0.0.1",
},
}
email, response, err := client.Email.Send(emailReq)
if err != nil {
return err
}
```
What's Implemented?
----------------
At the moment only a handful of the more common endpoints have been implemented. Open an
issue (or PR) if you required something that's missing.
- Send Email - [API Docs](http://developer.postmarkapp.com/developer-api-email.html#send-email) | [Example](examples/send-email/main.go)
- Send Email & Attachment - [API Docs](http://developer.postmarkapp.com/developer-api-email.html#send-email) | [Example](examples/send-email-attachment/main.go)
- Batch Emails - [API Docs](http://developer.postmarkapp.com/developer-api-email.html#batch-emails) | [Example](examples/batch-emails/main.go)
- Get Delivery Stats - [API Docs](http://developer.postmarkapp.com/developer-api-bounce.html#delivery-stats) | [Example](examples/bounce/main.go)
- Get Bounces - [API Docs](http://developer.postmarkapp.com/developer-api-bounce.html#bounces) | [Example](examples/bounce/main.go)
- Get Single Bounce - [API Docs](https://postmarkapp.com/developer/api/bounce-api#single-bounce)
- Get Bounce Dump - [API Docs](https://postmarkapp.com/developer/api/bounce-api#bounce-dump)
- Activate a Bounce - [API Docs](https://postmarkapp.com/developer/api/bounce-api#activate-bounce)
- Get Bounced Tags - [API Docs](https://postmarkapp.com/developer/api/bounce-api#bounced-tags)
- List Templates - [API Docs](https://postmarkapp.com/developer/api/templates-api#list-templates)
- Get Single Template - [API Docs](https://postmarkapp.com/developer/api/templates-api#get-template)
Thanks & Acknowledgements :ok_hand:
----------------
The packages's architecture is adapted from
[go-github](https://github.com/google/go-github), created by [Will
Norris](https://github.com/willnorris). :beers: