项目作者: mattevans

项目描述 :
✉️ Golang bindings for the Postmark API
高级语言: Go
项目地址: git://github.com/mattevans/postmark-go.git
创建时间: 2016-09-22T02:30:24Z
项目社区:https://github.com/mattevans/postmark-go

开源协议:MIT License

下载


postmark-go

GoDoc
Build Status
license

postmark-go is a Go client library for accessing the Postmark API (http://developer.postmarkapp.com/).

This is an unofficial library that is not affiliated with Postmark. Official libraries are available
here.

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.

Client + Authentication

  1. client := postmark.NewClient(
  2. postmark.WithClient(&http.Client{
  3. Transport: &postmark.AuthTransport{Token: "SERVER_API_TOKEN"},
  4. }),
  5. )

Example usage (with Template)

  1. emailReq := &postmark.Email{
  2. From: "mail@company.com",
  3. To: "jack@sparrow.com",
  4. TemplateID: 123456,
  5. TemplateModel: map[string]interface{}{
  6. "name": "Jack",
  7. "action_url": "http://click.company.com/welcome",
  8. },
  9. Tag: "onboarding",
  10. TrackOpens: true,
  11. Metadata: map[string]string{
  12. "client-id": "123456",
  13. "client-ip": "127.0.0.1",
  14. },
  15. }
  16. email, response, err := client.Email.Send(emailReq)
  17. if err != nil {
  18. return err
  19. }

Example usage (with HtmlBody)

  1. emailReq := &postmark.Email{
  2. From: "mail@company.com",
  3. To: "jack@sparrow.com",
  4. Subject: "My Test Email",
  5. HtmlBody: "<html><body><strong>Hello</strong> dear Postmark user.</body></html>",
  6. TextBody: "Hello dear Postmark user",
  7. Tag: "onboarding",
  8. TrackOpens: true,
  9. Metadata: map[string]string{
  10. "client-id": "123456",
  11. "client-ip": "127.0.0.1",
  12. },
  13. }
  14. email, response, err := client.Email.Send(emailReq)
  15. if err != nil {
  16. return err
  17. }

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.

Thanks & Acknowledgements :ok_hand:

The packages’s architecture is adapted from
go-github, created by Will
Norris
. :beers: