1Mailgun with Go
2===============
3
4[![Build Status](https://img.shields.io/travis/mailgun/mailgun-go/master.svg)](https://travis-ci.org/mailgun/mailgun-go)
5[![GoDoc](https://godoc.org/gopkg.in/mailgun/mailgun-go.v1?status.svg)](https://godoc.org/gopkg.in/mailgun/mailgun-go.v1)
6
7
8Go library for interacting with the [Mailgun](https://mailgun.com/) [API](https://documentation.mailgun.com/api_reference.html).
9
10# Sending mail via the mailgun CLI
11Export your API keys and domain
12```bash
13$ export MG_API_KEY=your-api-key
14$ export MG_DOMAIN=your-domain
15$ export MG_PUBLIC_API_KEY=your-public-key
16$ export MG_URL="https://api.mailgun.net/v3"
17```
18Send an email
19```bash
20$ echo -n 'Hello World' | mailgun send -s "Test subject" address@example.com
21```
22
23# Sending mail via the golang library
24```go
25package main
26
27import "gopkg.in/mailgun/mailgun-go.v1"
28
29mg := mailgun.NewMailgun(yourdomain, ApiKey, publicApiKey)
30message := mailgun.NewMessage(
31    "sender@example.com",
32    "Fancy subject!",
33    "Hello from Mailgun Go!",
34    "recipient@example.com")
35resp, id, err := mg.Send(message)
36if err != nil {
37    log.Fatal(err)
38}
39fmt.Printf("ID: %s Resp: %s\n", id, resp)
40```
41
42# Installation
43Install the go library
44```
45go get gopkg.in/mailgun/mailgun-go.v1
46```
47
48Install the mailgun CLI
49```
50go install github.com/mailgun/mailgun-go/cmd/mailgun/./...
51```
52
53# Testing
54
55*WARNING* - running the tests will cost you money!
56
57To run the tests various environment variables must be set. These are:
58
59* `MG_DOMAIN` is the domain name - this is a value registered in the Mailgun admin interface.
60* `MG_PUBLIC_API_KEY` is the public API key - you can get this value from the Mailgun admin interface.
61* `MG_API_KEY` is the (private) API key - you can get this value from the Mailgun admin interface.
62* `MG_EMAIL_TO` is the email address used in various sending tests.
63
64and finally
65
66* `MG_SPEND_MONEY` if this value is set the part of the test that use the API to actually send email
67will be run - be aware *this will count on your quota* and *this _will_ cost you money*.
68
69The code is released under a 3-clause BSD license. See the LICENSE file for more information.
70