Giter Site home page Giter Site logo

gosparkpost's Introduction

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.

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{"[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)
}

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

gosparkpost's People

Contributors

avezina-ubik avatar aydrian avatar cbroglie avatar jen20 avatar jgzamora avatar kakysha avatar macfisherman avatar mostafah avatar nexweb avatar richleland avatar vojtechvitek avatar yargevad avatar yepher avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.