SparkPost client library for the Go Programming Language
Go
Latest commit 2892490 Nov 15, 2016 @yargevad yargevad committed on GitHub Merge pull request #79 from SparkPost/ISSUE-78
support for public webhook event docs endpoint
Permalink
Failed to load latest commit information.
cmd add `--rfc822` option, takes a string or path to file; avoid sending … Oct 28, 2016
events Remove ErrWebhookValidation (see #52) May 14, 2016
examples more on the "why" of cc and bcc Jun 3, 2016
helpers/loadmsg remove dkim from message loading helper Jul 28, 2016
test start work to support public event docs endpoint Nov 15, 2016
.gitignore ignore vim swap files Oct 5, 2015
.travis.yml bump travis's required go version up to 1.5 since that's when mime/qu… Mar 24, 2016
AUTHORS.rst Issue # 26: Fixes problem where Timestamp was getting decoded as int6… Feb 11, 2016
CONTRIBUTING.md Fixes some typo for branching project Feb 11, 2016
LICENSE apache 2.0 license, with message systems copyright Oct 6, 2015
README.rst update doc links in main readme; update title in `sparks` summary; ad… Jun 3, 2016
common.go `Response.Results` needs to be an `interface{}`, not `map[string]inte… Oct 12, 2016
deliverability-metrics.go make DoMetricsRequest private Mar 15, 2016
event_docs.go explicitly tag EventGroup.Events for json parsing Nov 15, 2016
event_docs_test.go support for webhook event documentation endpoint Nov 15, 2016
message_events.go Fix typo Mar 15, 2016
message_events_test.go Implement EventsPage.Next() Mar 15, 2016
recipient_lists.go `Response.Results` needs to be an `interface{}`, not `map[string]inte… Oct 12, 2016
recipient_lists_test.go temporarily disable tests that make api calls, so travis reports buil… Jan 22, 2016
subaccounts.go `Response.Results` needs to be an `interface{}`, not `map[string]inte… Oct 12, 2016
suppression_list.go parse out any error responses from GET requests Oct 12, 2016
suppression_list_test.go test 404 suppression response; add helper for test error cases that d… Oct 12, 2016
template_from_json_test.go remove hyphen from repo name so it can be used as a go package name Jan 9, 2016
templates.go `Response.Results` needs to be an `interface{}`, not `map[string]inte… Oct 12, 2016
templates_test.go support for using an Address in Content.From (ignores Address.HeaderTo) Jul 27, 2016
test_server.go test 404 suppression response; add helper for test error cases that d… Oct 12, 2016
transmissions.go `Response.Results` needs to be an `interface{}`, not `map[string]inte… Oct 12, 2016
transmissions_test.go temporarily disable tests that make api calls, so travis reports buil… Jan 22, 2016
webhooks.go Fixes duplicate code in webhooks.go Mar 15, 2016

README.rst

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

SparkPost Go API client

Slack Community

The official Go package for using the SparkPost API.

Installation

Install from GitHub using go get:

$ go get github.com/SparkPost/gosparkpost

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 (
  "log"
  "os"

  sp "github.com/SparkPost/gosparkpost"
)

func main() {
  // Get our API key from the environment; configure.
  apiKey := os.Getenv("SPARKPOST_API_KEY")
  cfg := &sp.Config{
    BaseUrl:    "https://api.sparkpost.com",
    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{"someone@somedomain.com"},
    Content: sp.Content{
      HTML:    "<p>Hello world</p>",
      From:    "test@sparkpostbox.com",
      Subject: "Hello from gosparkpost",
    },
  }
  id, _, err := client.Send(tx)
  if err != nil {
    log.Fatal(err)
  }

  // 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)
}

Documentation

Contribute

TL;DR:

  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 https://github.com/SparkPost/gosparkpost
  4. Add your fork as a remote - git remote add fork http://github.com/YOURID/gosparkpost
  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