Categorygithub.com/luminalhq/gosparkpost
modulepackage
0.0.0-20190325180146-d3f2b2dcc000
Repository: https://github.com/luminalhq/gosparkpost.git
Documentation: pkg.go.dev

# README

.. image:: https://www.sparkpost.com/sites/default/files/attachments/SparkPost_Logo_2-Color_Gray-Orange_RGB.svg :target: https://www.sparkpost.com :width: 200px

Sign up_ for a SparkPost account and visit our Developer Hub_ for even more content.

.. _Sign up: https://app.sparkpost.com/join?plan=free-0817?src=Social%20Media&sfdcid=70160000000pqBb&pc=GitHubSignUp&utm_source=github&utm_medium=social-media&utm_campaign=github&utm_content=sign-up .. _Developer Hub: https://developers.sparkpost.com

SparkPost Go API client

.. image:: https://travis-ci.org/SparkPost/gosparkpost.svg?branch=master :target: https://travis-ci.org/SparkPost/gosparkpost :alt: Build Status

.. image:: https://coveralls.io/repos/SparkPost/gosparkpost/badge.svg?branch=master&service=github :target: https://coveralls.io/github/SparkPost/gosparkpost?branch=master :alt: Code Coverage

The official Go package for using the SparkPost API.

Installation

Install from GitHub using go get_:

.. code-block:: bash

$ go get github.com/SparkPost/gosparkpost

.. _go get: https://golang.org/cmd/go/#hdr-Download_and_install_packages_and_dependencies

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.

.. _API & SMTP: https://app.sparkpost.com/#/configuration/credentials

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:

.. code-block:: go

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{"[email protected]"},
    Content: sp.Content{
      HTML:    "<p>Hello world</p>",
      From:    "[email protected]",
      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)
}

.. _transmissions API: https://www.sparkpost.com/api#/reference/transmissions

Documentation

  • SparkPost API Reference_
  • Code samples_
  • Command-line tool: sparks_

.. _SparkPost API Reference: https://developers.sparkpost.com/api .. _Code samples: examples/README.md .. _Command-line tool: sparks: cmd/sparks/README.md

Contribute

TL;DR:

#. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug. #. Fork the repository. #. Go get the original code - go get https://github.com/SparkPost/gosparkpost #. Add your fork as a remote - git remote add fork http://github.com/YOURID/gosparkpost #. Make your changes in a branch on your fork #. Write a test which shows that the bug was fixed or that the feature works as expected. #. Push your changes - git push fork HEAD #. Send a pull request. Make sure to add yourself to AUTHORS.

More on the contribution process_

.. _the repository: https://github.com/SparkPost/gosparkpost .. _AUTHORS: AUTHORS.rst .. _contribution process: CONTRIBUTING.md

# Packages

No description provided by the author
Package events defines a struct for each type of event and provides various other helper functions.
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

Is2XX returns true if the provided HTTP response code is in the range 200-299.
NewConfig builds a Config object using the provided map.
ParseAddress parses the various allowable Content.From values.
ParseContent asserts that Transmission.Content is valid.
ParseFrom parses the various allowable Content.From values.
ParseRecipients asserts that Transmission.Recipients is valid.
Tokenize splits a string that may contain Handlebars-style template code into (you guessed it) tokens for further processing.

# Constants

No description provided by the author
No description provided by the author

# Variables

No description provided by the author
https://www.sparkpost.com/api#/reference/message-events.
https://www.sparkpost.com/api#/reference/message-events.
No description provided by the author
https://www.sparkpost.com/api#/reference/recipient-lists.
SubaccountGrants contains the grants that will be given to new subaccounts by default.
SubaccountsPathFormat provides an easy way to fill out the path including the version.
SubaccountStatuses contains valid subaccount statuses.
SuppressionListsPathFormat https://developers.sparkpost.com/api/#/reference/suppression-list.
https://www.sparkpost.com/api#/reference/templates.
TransmissionsPathFormat https://www.sparkpost.com/api#/reference/transmissions.
WebhooksPathFormat is the path prefix used for webhook-related requests, with a format string for the API version.

# Structs

Address describes the nested object way of specifying the Recipient's email address.
Attachment contains metadata and the contents of the file to attach.
Client contains connection, configuration, and authentication information.
Config includes all information necessary to make an API request.
Content is what you'll send to your Recipients.
ContentToken represents a piece of content, with one of the types defined above.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
From describes the nested object way of specifying the From header.
Macro enables user-defined functions to run on Template.Content before sending to the SparkPost API.
No description provided by the author
No description provided by the author
PreviewOptions contains the required subsitution_data object to preview a template.
Recipient represents one email (you guessed it) recipient.
RecipientList is the JSON structure accepted by and returned from the SparkPost Recipient Lists API.
Response contains information about the last HTTP response.
SPError mirrors the error format returned by SparkPost APIs.
Subaccount is the JSON structure accepted by and returned from the SparkPost Subaccounts API.
SuppressionEntry stores a recipient’s opt-out preferences.
SuppressionPage wraps suppression entries and response meta information.
Template is the JSON structure accepted by and returned from the SparkPost Templates API.
TmplOptions specifies settings to apply to this Template.
Transmission is the JSON structure accepted by and returned from the SparkPost Transmissions API.
TxOptions specifies settings to apply to this Transmission.
WebhookCommon contains fields common to all response types.
WebhookDetailWrapper is passed into and updated by the WebhookDetail method, using results returned from the API.
WebhookItem defines how webhook objects will be returned, as well as how they must be sent.
WebhookListWrapper is passed into and updated by the Webhooks method, using results returned from the API.
WebhookStatus defines how the status of a webhook will be returned.
WebhookStatusWrapper is passed into and updated by the WebhookStatus method, using results returned from the API.
WritableSuppressionEntry stores a recipient’s opt-out preferences.

# Type aliases

ErrorCode is aliased to enable custom UnmarshalJSON.
InlineImage contains metadata and the contents of the image to make available for inline use.
RFC3339 formats time.Time values as expected by the SparkPost API.
SPErrors is the plural of SPError.
TokenType differentiates between static content and macros that require extra processing.