Categorygithub.com/mattevans/postmark-go
modulepackage
1.0.0
Repository: https://github.com/mattevans/postmark-go.git
Documentation: pkg.go.dev

# README

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

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

Example usage (with Template)

emailReq := &postmark.Email{
  From:       "[email protected]",
  To:         "[email protected]",
  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)

emailReq := &postmark.Email{
  From:       "[email protected]",
  To:         "[email protected]",
  Subject:    "My Test Email",
  HtmlBody:   "<html><body><strong>Hello</strong> dear Postmark user.</body></html>",
  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.

Thanks & Acknowledgements :ok_hand:

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

# Packages

No description provided by the author

# Functions

CheckResponse checks the API response for errors.
NewClient creates a new Client with the appropriate connection details and services used for communicating with the API.
NewOptions returns a new Options with defaults and supplied overrides.
WithBackendURL allows you to set a custom backend URL.
WithClient allows you to set a custom http client.
WithUserAgent allows you to set a custom user agent.

# Structs

AuthTransport holds a authentication information for Postmark API.
Bounce represents a BounceType in further detail.
BounceActivated represents a bounce that has been reactivated.
BounceDeliveryStats represents a collection of bounce stats.
BounceDump represents a the raw source of bounce.
Bounces represents a slice of bounces and a given count.
BounceType represents the type of bounce with a count.
Client holds a connection to the Postmark API.
Email is the set of parameters that can be used when sending an email.
EmailAttachment represents the values for an email attachment.
EmailHeader represents the values for an email header.
EmailResponse is the set of parameters that is used in response to a send request.
An ErrorResponse reports the error caused by an API request.
Options for our client.
Response is a Postmark response.
Template represents a templates in further detail.
TemplateOverview represents overview/identifying information about a template.
Templates represents a slice of templates and a given count.

# Type aliases

BounceService handles communication with the bounce related methods of the Postmark API (http://developer.postmarkapp.com/developer-api-bounce.html).
EmailService handles communication with the email related methods of the Postmark API (http://developer.postmarkapp.com/developer-api-email.html).
Option to set an optional client value.
TemplateService handles communication with the template related methods of the Postmark API (https://postmarkapp.com/developer/api/templates-api).