Skip to content
SparkPost client library for the Go Programming Language
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
events fix vet warnings May 22, 2018
examples more on the "why" of cc and bcc Jun 3, 2016
helpers fix vet warnings May 22, 2018
test improve MessageEventsSearch tests Apr 27, 2017
.travis.yml multiple patterns should be comma-separated Mar 31, 2017
AUTHORS.rst Issue # 26: Fixes problem where Timestamp was getting decoded as int6… Feb 11, 2016 Fixes some typo for branching project Feb 11, 2016
LICENSE apache 2.0 license, with message systems copyright Oct 6, 2015
common.go first cut of macros feature Jan 26, 2018
common_test.go custom unmarshaler for error code, since it can be an integer in some… Oct 30, 2017
del_metrics_test.go assert that we have the expected number of errors Jan 20, 2017
event_docs.go avoid calling `ReadBody` directly, instead return the body from `Asse… May 10, 2017
event_docs_test.go the rest of the "context in its own param" changes Feb 18, 2017
macros.go close `httptest` server when we're done with it; add/update comments Jan 31, 2018
macros_test.go ioutil.ReadAll eats EOFs Jan 31, 2018
message_events.go pull some repeated code out into a helper Oct 19, 2017
message_events_test.go fix vet warnings May 22, 2018
recipient_lists.go avoid calling `ReadBody` directly, instead return the body from `Asse… May 10, 2017
subaccounts.go Client.HttpPutJson to replace duplicated PUTs Oct 19, 2017
suppression_list.go Client.HttpPutJson to replace duplicated PUTs Oct 19, 2017
suppression_list_test.go move json files into a subdirectory under `test` Apr 11, 2017
transmissions.go Merge pull request #136 from bontibon/veterrors2 May 22, 2018
transmissions_test.go merge master Mar 31, 2017
webhooks.go avoid calling `ReadBody` directly, instead return the body from `Asse… May 10, 2017
webhooks_test.go tests for WebhookDetail, Webhooks; add some sleight of hand to make h… Apr 26, 2017


Sign up for a SparkPost account and visit our Developer Hub for even more content.

SparkPost Go API client

Build Status Code Coverage

The official Go package for using the SparkPost API.


Install from GitHub using go get:

$ go get

Get a key

Go to API & SMTP in the SparkPost app and create an API key. We recommend using the SPARKPOST_API_KEY environment variable. The example code below shows how to set this up.

Send a message

Here at SparkPost, our "send some messages" api is called the transmissions API - let's use it to send a friendly test message:

package main

import (

  sp ""

func main() {
  // Get our API key from the environment; configure.
  apiKey := os.Getenv("SPARKPOST_API_KEY")
  cfg := &sp.Config{
    BaseUrl:    "",
    ApiKey:     apiKey,
    ApiVersion: 1,
  var client sp.Client
  err := client.Init(cfg)
  if err != nil {
    log.Fatalf("SparkPost client init failed: %s\n", err)

  // Create a Transmission using an inline Recipient List
  // and inline email Content.
  tx := &sp.Transmission{
    Recipients: []string{""},
    Content: sp.Content{
      HTML:    "<p>Hello world</p>",
      From:    "",
      Subject: "Hello from gosparkpost",
  id, _, err := client.Send(tx)
  if err != nil {

  // The second value returned from Send
  // has more info about the HTTP response, in case
  // you'd like to see more than the Transmission id.
  log.Printf("Transmission sent with id [%s]\n", id)




  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug.
  2. Fork the repository.
  3. Go get the original code - go get
  4. Add your fork as a remote - git remote add fork
  5. Make your changes in a branch on your fork
  6. Write a test which shows that the bug was fixed or that the feature works as expected.
  7. Push your changes - git push fork HEAD
  8. Send a pull request. Make sure to add yourself to AUTHORS.

More on the contribution process

You can’t perform that action at this time.