mailgun

package module
v5.10.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 12, 2026 License: BSD-3-Clause Imports: 25 Imported by: 5

README

Mailgun with Go

GoDoc Build Status

Go library for interacting with the Mailgun API.

Installation

If you are using Go Modules make sure you include the /v5 at the end of your import paths

go get github.com/mailgun/mailgun-go/v5

Usage

Send a message
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/mailgun/mailgun-go/v5"
)

// Your available domain names can be found here:
// (https://app.mailgun.com/app/domains)
var yourDomain = "your-domain-name" // e.g. mg.yourcompany.com

// You can find the Private API Key in your Account Menu, under "Settings":
// (https://app.mailgun.com/settings/api_security)
var privateAPIKey = "your-private-key"

func main() {
	// Create an instance of the Mailgun Client
	mg := mailgun.NewMailgun(privateAPIKey)

	// When you have an EU domain, you must specify the endpoint:
	// err := mg.SetAPIBase(mailgun.APIBaseEU)

	sender := "[email protected]"
	subject := "Fancy subject!"
	body := "Hello from Mailgun Go!"
	recipient := "[email protected]"

	// The message object allows you to add attachments and Bcc recipients
	message := mailgun.NewMessage(yourDomain, sender, subject, body, recipient)

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()

	// Send the message with a 10-second timeout
	resp, err := mg.Send(ctx, message)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("ID: %s Resp: %s\n", resp.ID, resp.Message)
}
Get Events
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/mailgun/mailgun-go/v5"
	"github.com/mailgun/mailgun-go/v5/events"
)

func main() {
	// You can find the Private API Key in your Account Menu, under "Settings":
	// (https://app.mailgun.com/settings/api_security)
	mg := mailgun.NewMailgun("your-private-key")

	it := mg.ListEvents("your-domain.com", &mailgun.ListEventOptions{Limit: 100})

	var page []events.Event

	// The entire operation should not take longer than 30 seconds
	ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
	defer cancel()

	// For each page of 100 events
	for it.Next(ctx, &page) {
		for _, e := range page {
			// You can access some fields via the interface
			fmt.Printf("Event: '%s' TimeStamp: '%s'\n", e.GetName(), e.GetTimestamp())

			// and you can act upon each event by type
			switch event := e.(type) {
			case *events.Accepted:
				fmt.Printf("Accepted: auth: %t\n", event.Flags.IsAuthenticated)
			case *events.Delivered:
				fmt.Printf("Delivered transport: %s\n", event.Envelope.Transport)
			case *events.Failed:
				fmt.Printf("Failed reason: %s\n", event.Reason)
			case *events.Clicked:
				fmt.Printf("Clicked GeoLocation: %s\n", event.GeoLocation.Country)
			case *events.Opened:
				fmt.Printf("Opened GeoLocation: %s\n", event.GeoLocation.Country)
			case *events.Rejected:
				fmt.Printf("Rejected reason: %s\n", event.Reject.Reason)
			case *events.Stored:
				fmt.Printf("Stored URL: %s\n", event.Storage.URL)
			case *events.Unsubscribed:
				fmt.Printf("Unsubscribed client OS: %s\n", event.ClientInfo.ClientOS)
			}
		}
	}
}
Event Polling

The mailgun library has built-in support for polling the events api

package main

import (
	"context"
	"log"
	"time"

	"github.com/mailgun/mailgun-go/v5"
	"github.com/mailgun/mailgun-go/v5/events"
)

func main() {
	// You can find the Private API Key in your Account Menu, under "Settings":
	// (https://app.mailgun.com/settings/api_security)
	mg := mailgun.NewMailgun("your-private-key")

	begin := time.Now().Add(time.Second * -3)

	// Very short poll interval
	it := mg.PollEvents("your-domain.com", &mailgun.ListEventOptions{
		// Only events with a timestamp after this date/time will be returned
		Begin: begin,
		// How often we poll the api for new events
		PollInterval: time.Second * 30,
	})

	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	// Poll until our email event arrives
	var page []events.Event
	for it.Poll(ctx, &page) {
		for _, e := range page {
			log.Printf("Got an event: %q (%q)", e.GetName(), e.GetID())
			// Do something with event
		}
	}
}
Email Validations
package main

import (
	"context"
	"fmt"
	"time"

	"github.com/mailgun/mailgun-go/v5"
)

// Your plan should include email validations.
// Use your Mailgun API key. You can find the Mailgun API keys in your Account Menu, under "Settings":
// (https://app.mailgun.com/settings/api_security)
var apiKey = "your-api-key"

func main() {
	// Create an instance of the Validator
	mg := mailgun.NewMailgun("your-private-key")

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()

	email, err := mg.ValidateEmail(ctx, "[email protected]", false)
	if err != nil {
		panic(err)
	}
	fmt.Printf("Risk: %t\n", email.Risk)
}
Webhook Handling
package main

import (
	"encoding/json"
	"fmt"
	"net/http"
	"os"

	"github.com/mailgun/mailgun-go/v5"
	"github.com/mailgun/mailgun-go/v5/events"
	"github.com/mailgun/mailgun-go/v5/mtypes"
)

func main() {
	// You can find the Private API Key in your Account Menu, under "Settings":
	// (https://app.mailgun.com/settings/api_security)
	mg := mailgun.NewMailgun("private-api-key")
	mg.SetWebhookSigningKey("webhook-signing-key")

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		var payload mtypes.WebhookPayload
		if err := json.NewDecoder(r.Body).Decode(&payload); err != nil {
			fmt.Printf("decode JSON error: %s", err)
			w.WriteHeader(http.StatusNotAcceptable)
			return
		}

		verified, err := mg.VerifyWebhookSignature(payload.Signature)
		if err != nil {
			fmt.Printf("verify error: %s\n", err)
			w.WriteHeader(http.StatusNotAcceptable)
			return
		}

		if !verified {
			w.WriteHeader(http.StatusNotAcceptable)
			fmt.Printf("failed verification %+v\n", payload.Signature)
			return
		}

		fmt.Printf("Verified Signature\n")

		// Parse the event provided by the webhook payload
		e, err := events.ParseEvent(payload.EventData)
		if err != nil {
			fmt.Printf("parse event error: %s\n", err)
			return
		}

		switch event := e.(type) {
		case *events.Accepted:
			fmt.Printf("Accepted: auth: %t\n", event.Flags.IsAuthenticated)
		case *events.Delivered:
			fmt.Printf("Delivered transport: %s\n", event.Envelope.Transport)
		}
	})

	fmt.Println("Serve on :9090...")
	if err := http.ListenAndServe(":9090", nil); err != nil {
		fmt.Printf("serve error: %s\n", err)
		os.Exit(1)
	}
}
Sending HTML templates
package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/mailgun/mailgun-go/v5"
)

// Your available domain names can be found here:
// (https://app.mailgun.com/app/domains)
var yourDomain = "your-domain-name" // e.g. mg.yourcompany.com

// You can find the Private API Key in your Account Menu, under "Settings":
// (https://app.mailgun.com/settings/api_security)
var privateAPIKey = "your-private-key"

func main() {
	// Create an instance of the Mailgun Client
	mg := mailgun.NewMailgun(privateAPIKey)

	sender := "[email protected]"
	subject := "HTML email!"
	recipient := "[email protected]"

	message := mailgun.NewMessage(yourDomain, sender, subject, "", recipient)
	body := `
<html>
<body>
	<h1>Sending HTML emails with Mailgun</h1>
	<p style="color:blue; font-size:30px;">Hello world</p>
	<p style="font-size:30px;">More examples can be found <a href="https://documentation.mailgun.com/en/latest/api-sending.html#examples">here</a></p>
</body>
</html>
`

	message.SetHTML(body)

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()

	// Send the message with a 10-second timeout
	resp, err := mg.Send(ctx, message)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("ID: %s Resp: %s\n", resp.ID, resp.Message)
}
Using Templates

Templates enable you to create message templates on your Mailgun account and then populate the data variables at send-time. This allows you to have your layout and design managed on the server and handle the data on the client. The template variables are added as a JSON stringified X-Mailgun-Variables header. For example, if you have a template to send a password reset link, you could do the following:

package main

import (
	"context"
	"fmt"
	"log"
	"time"

	"github.com/mailgun/mailgun-go/v5"
)

// Your available domain names can be found here:
// (https://app.mailgun.com/app/domains)
var yourDomain = "your-domain-name" // e.g. mg.yourcompany.com

// You can find the Private API Key in your Account Menu, under "Settings":
// (https://app.mailgun.com/settings/api_security)
var privateAPIKey = "your-private-key"

func main() {
	// Create an instance of the Mailgun Client
	mg := mailgun.NewMailgun(privateAPIKey)

	sender := "[email protected]"
	subject := "Fancy subject!"
	body := ""
	recipient := "[email protected]"

	// The message object allows you to add attachments and Bcc recipients
	message := mailgun.NewMessage(yourDomain, sender, subject, body, recipient)
	message.SetTemplate("passwordReset")
	err := message.AddTemplateVariable("passwordResetLink", "some link to your site unique to your user")
	if err != nil {
		log.Fatal(err)
	}

	ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
	defer cancel()

	// Send the message with a 10-second timeout
	resp, err := mg.Send(ctx, message)
	if err != nil {
		log.Fatal(err)
	}

	fmt.Printf("ID: %s Resp: %s\n", resp.ID, resp.Message)
}

The official mailgun documentation includes examples using this library. Go here.

EU Region

European customers will need to change the default API Base to access your domains

mg := mailgun.NewMailgun("private-api-key")
mg.SetAPIBase(mailgun.APIBaseEU)

Major Version Migration Notes

We are trying to keep breaking changes to a minimum, but sometimes they are necessary.

We are guaranteeing that there will be no breaking changes within a major version.

v4 to v5 Migration

List of changes are in Release v5.0.0.

How to migrate
  1. Upgrade to the latest v4 release (v4.23.0) first.
  2. Get rid of all deprecated code usage. We recommend using staticcheck linter SA1019 check for that (or just look for // Deprecated: comments in the code) and follow the recommendations there. This should make the major version bump go more smoothly.
  3. Update your import paths to use /v5 at the end, e.g.
    import "github.com/mailgun/mailgun-go/v5"
    

Testing

WARNING - running the tests will cost you money!

To run the tests various environment variables must be set. These are:

  • MG_DOMAIN is the domain name - this is a value registered in the Mailgun admin interface.
  • MG_API_KEY is the Private API key - you can get this value from the Mailgun security page
  • MG_EMAIL_TO is the email address used in various sending tests.

and finally

  • MG_SPEND_MONEY if this value is set the part of the test that use the API to actually send email will be run - be aware this will count on your quota and this will cost you money.

The code is released under a 3-clause BSD license. See the LICENSE file for more information.

Documentation

Overview

Package mailgun provides methods for interacting with the Mailgun API. It automates the HTTP request/response cycle, encodings, and other details needed by the API. This SDK lets you do everything the API lets you, in a more Go-friendly way.

For further information please see the Mailgun documentation at http://documentation.mailgun.com/

Original Author: Michael Banzon
Contributions:   Samuel A. Falvo II <sam.falvo %at% rackspace.com>
                 Derrick J. Wippler <thrawn01 %at% gmail.com>

Examples

All functions and method have a corresponding test, so if you don't find an example for a function you'd like to know more about, please check for a corresponding test. Of course, contributions to the documentation are always welcome as well. Feel free to submit a pull request or open a Github issue if you cannot find an example to suit your needs.

List iterators

Most methods that begin with `List` return an iterator which simplfies paging through large result sets returned by the mailgun API. Most `List` methods allow you to specify a `Limit` parameter which as you'd expect, limits the number of items returned per page. Note that, at present, Mailgun imposes its own cap of 100 items per page, for all API endpoints.

For example, the following iterates over all pages of events 100 items at a time

mg := mailgun.NewMailgun("your-api-key")
it := mg.ListEvents(&mailgun.ListEventOptions{Limit: 100})

// The entire operation should not take longer than 30 seconds
ctx, cancel := context.WithTimeout(context.Background(), time.Second*30)
defer cancel()

// For each page of 100 events
var page []mailgun.Event
for it.Next(ctx, &page) {
  for _, e := range page {
    // Do something with 'e'
  }
}

License

Copyright (c) 2013-2019, Michael Banzon. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

* Neither the names of Mailgun, Michael Banzon, nor the names of their contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Index

Constants

View Source
const (
	// APIBase - base URL the library uses to contact mailgun. Use SetAPIBase() to override
	APIBase   = "https://api.mailgun.net"
	APIBaseUS = APIBase
	APIBaseEU = "https://api.eu.mailgun.net"

	OnBehalfOfHeader = "X-Mailgun-On-Behalf-Of"
)
View Source
const MaxNumberOfRecipients = 1000

MaxNumberOfRecipients represents the largest batch of recipients that Mailgun can support in a single API call. This figure includes To:, Cc:, Bcc:, etc. recipients.

View Source
const MaxNumberOfTags = 10

MaxNumberOfTags represents the maximum number of tags that can be added for a message

View Source
const UserAgent = "mailgun-go/" + Version

The UserAgent identifies the client to the server, for logging purposes. In the event of problems requiring a human administrator's assistance, this user agent allows them to identify the client from human-generated activity.

View Source
const Version = "5.0.0"

Version of current release TODO(vtopc): automate this

Variables

View Source
var Debug = false

Debug set true to write the HTTP requests in curl for to stdout

View Source
var ErrEmptyParam = errors.New("empty or illegal parameter")

ErrEmptyParam is returned when a required parameter is missing.

View Source
var ErrInvalidMessage = errors.New("message not valid")

ErrInvalidMessage is returned by `Send()` when the `mailgun.CommonMessage` struct is incomplete

Functions

func GetStatusFromErr

func GetStatusFromErr(err error) int

GetStatusFromErr extracts the http status code from error object

func TimeToFloat

func TimeToFloat(t time.Time) float64

TimeToFloat given time.Time{} return a float64 as given in mailgun event timestamps

Types

type AllDomainsKeysIterator added in v5.10.0

type AllDomainsKeysIterator struct {
	mtypes.ListAllDomainsKeysResponse
	// contains filtered or unexported fields
}

AllDomainsKeysIterator is a list iterator for https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/domain-keys/get-v1-dkim-keys

func (*AllDomainsKeysIterator) Err added in v5.10.0

func (ri *AllDomainsKeysIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*AllDomainsKeysIterator) First added in v5.10.0

func (ri *AllDomainsKeysIterator) First(ctx context.Context, items *[]mtypes.DomainKey) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*AllDomainsKeysIterator) Last added in v5.10.0

func (ri *AllDomainsKeysIterator) Last(ctx context.Context, items *[]mtypes.DomainKey) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*AllDomainsKeysIterator) Next added in v5.10.0

func (ri *AllDomainsKeysIterator) Next(ctx context.Context, items *[]mtypes.DomainKey) bool

Next retrieves the next page of items from the api. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*AllDomainsKeysIterator) Previous added in v5.10.0

func (ri *AllDomainsKeysIterator) Previous(ctx context.Context, items *[]mtypes.DomainKey) bool

Previous retrieves the previous page of items from the api. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type BouncesIterator

type BouncesIterator struct {
	mtypes.BouncesListResponse
	// contains filtered or unexported fields
}

func (*BouncesIterator) Err

func (ci *BouncesIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*BouncesIterator) First

func (ci *BouncesIterator) First(ctx context.Context, items *[]mtypes.Bounce) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*BouncesIterator) Last

func (ci *BouncesIterator) Last(ctx context.Context, items *[]mtypes.Bounce) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*BouncesIterator) Next

func (ci *BouncesIterator) Next(ctx context.Context, items *[]mtypes.Bounce) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*BouncesIterator) Previous

func (ci *BouncesIterator) Previous(ctx context.Context, items *[]mtypes.Bounce) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type BufferAttachment

type BufferAttachment struct {
	Filename string
	Buffer   []byte
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client bundles data needed by a large number of methods in order to interact with the Mailgun API.

func NewMailgun

func NewMailgun(apiKey string) *Client

NewMailgun creates a new client instance.

func NewMailgunFromEnv

func NewMailgunFromEnv() (*Client, error)

NewMailgunFromEnv returns a new Mailgun client using the environment variables MG_API_KEY, MG_URL, and MG_WEBHOOK_SIGNING_KEY

func (*Client) APIBase

func (mg *Client) APIBase() string

APIBase returns the API Base URL configured for this client.

func (*Client) APIKey

func (mg *Client) APIKey() string

APIKey returns the API key configured for this client.

func (*Client) ActivateDomainKey added in v5.10.0

func (mg *Client) ActivateDomainKey(ctx context.Context, domain, dkimSelector string) error

ActivateDomainKey deactivates a domain key for the given domain

func (*Client) AddAlert added in v5.3.0

func (*Client) AddBounce

func (mg *Client) AddBounce(ctx context.Context, domain, address, code, bounceError string) error

AddBounce files a bounce report. Address identifies the intended recipient of the message that bounced. Code corresponds to the numeric response given by the e-mail server which rejected the message. Error provides the corresponding human-readable reason for the problem. For example, here's how the these two fields relate. Suppose the SMTP server responds with an error, as below. Then, ...

 550  Requested action not taken: mailbox unavailable
\___/\_______________________________________________/
  |                         |
  `-- Code                  `-- Error

Note that both code and error exist as strings, even though code will report as a number.

func (*Client) AddBounces

func (mg *Client) AddBounces(ctx context.Context, domain string, bounces []mtypes.Bounce) error

AddBounces adds a list of bounces to the bounce list

func (*Client) AddDomainIP

func (mg *Client) AddDomainIP(ctx context.Context, domain, ip string) error

AddDomainIP assign a dedicated IP to the domain specified.

func (*Client) AddDomainToMonitoring added in v5.4.0

AddDomainToMonitoring adds a single domain to an account

func (*Client) AddOverrideHeader

func (mg *Client) AddOverrideHeader(k, v string)

AddOverrideHeader allows the user to specify additional headers that will be included in the HTTP request This is mostly useful for testing the Mailgun API hosted at a different endpoint.

func (*Client) AddTemplateVersion

func (mg *Client) AddTemplateVersion(ctx context.Context, domain, templateName string, version *mtypes.TemplateVersion) error

AddTemplateVersion adds a template version to a template

func (*Client) ChangeCredentialPassword

func (mg *Client) ChangeCredentialPassword(ctx context.Context, domain, login, password string) error

ChangeCredentialPassword attempts to alter the indicated credential's password.

func (*Client) CreateAPIKey added in v5.5.0

func (mg *Client) CreateAPIKey(ctx context.Context, role string, opts *CreateAPIKeyOptions) (mtypes.APIKey, error)

func (*Client) CreateComplaint

func (mg *Client) CreateComplaint(ctx context.Context, domain, address string) error

CreateComplaint registers the specified address as a recipient who has complained of receiving spam from your domain.

func (*Client) CreateComplaints

func (mg *Client) CreateComplaints(ctx context.Context, domain string, addresses []string) error

func (*Client) CreateCredential

func (mg *Client) CreateCredential(ctx context.Context, domain, login, password string) error

CreateCredential attempts to create associate a new principle with your domain.

func (*Client) CreateDomain

func (mg *Client) CreateDomain(ctx context.Context, domain string, opts *CreateDomainOptions) (mtypes.GetDomainResponse, error)

CreateDomain instructs Mailgun to create a new domain for your account. The name parameter identifies the domain. The smtpPassword parameter provides an access credential for the domain. The spamAction domain must be one of Delete, Tag, or Disabled. The wildcard parameter instructs Mailgun to treat all subdomains of this domain uniformly if true, and as different domains if false.

func (*Client) CreateDomainKey added in v5.10.0

func (mg *Client) CreateDomainKey(ctx context.Context, domain, dkimSelector string, opts *CreateDomainKeyOptions) (mtypes.DomainKey, error)

CreateDomainKey creates a domain key for the given domain

func (*Client) CreateExport

func (mg *Client) CreateExport(ctx context.Context, url string) error

CreateExport creates an export based on the URL given

func (*Client) CreateIPWarmup added in v5.8.0

func (mg *Client) CreateIPWarmup(ctx context.Context, ip string) error

func (*Client) CreateMailingList

func (mg *Client) CreateMailingList(ctx context.Context, list mtypes.MailingList) (mtypes.MailingList, error)

CreateMailingList creates a new mailing list under your Mailgun account. You need specify only the Address and Name members of the prototype; Description, AccessLevel and ReplyPreference are optional. If unspecified, the Description remains blank, while AccessLevel defaults to Everyone and ReplyPreference defaults to List.

func (*Client) CreateMember

func (mg *Client) CreateMember(ctx context.Context, merge bool, listAddress string, member mtypes.Member) error

CreateMember registers a new member of the indicated mailing list. If merge is set to true, then the registration may update an existing Member's settings. Otherwise, an error will occur if you attempt to add a member with a duplicate e-mail address.

func (*Client) CreateMemberList

func (mg *Client) CreateMemberList(ctx context.Context, u *bool, listAddress string, newMembers []any) error

CreateMemberList registers multiple Members and non-Member members to a single mailing list in a single round-trip. u indicates if the existing members should be updated or duplicates should be updated. Use All to elect not to provide a default. The newMembers list can take one of two JSON-encodable forms: a slice of strings, or a slice of Member structures. If a simple slice of strings is passed, each string refers to the member's e-mail address. Otherwise, each Member needs to have at least the Address field filled out. Other fields are optional, but may be set according to your needs.

func (*Client) CreateRoute

func (mg *Client) CreateRoute(ctx context.Context, route mtypes.Route) (_ mtypes.Route, err error)

CreateRoute installs a new route for your domain. The route structure you provide serves as a template, and only a subset of the fields influence the operation. See the Route structure definition for more details.

func (*Client) CreateSubaccount

func (mg *Client) CreateSubaccount(ctx context.Context, subaccountName string) (mtypes.SubaccountResponse, error)

CreateSubaccount instructs Mailgun to create a new account (Subaccount) that is linked to the primary account. Subaccounts are child accounts that share the same plan and usage allocations as the primary, but have their own assets (sending domains, unique users, API key, SMTP credentials, settings, statistics and site login). All you need is the name of the subaccount.

func (*Client) CreateTemplate

func (mg *Client) CreateTemplate(ctx context.Context, domain string, template *mtypes.Template) error

Create a new template which can be used to attach template versions to

func (*Client) CreateUnsubscribe

func (mg *Client) CreateUnsubscribe(ctx context.Context, domain, address, tag string) error

CreateUnsubscribe adds an e-mail address to the domain's unsubscription table.

func (*Client) CreateUnsubscribes

func (mg *Client) CreateUnsubscribes(ctx context.Context, domain string, unsubscribes []mtypes.Unsubscribe) error

CreateUnsubscribes adds multiple e-mail addresses to the domain's unsubscription table. TODO(vtopc): Doc says it's domain ID, not name. Rename arg to clarify.

https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/unsubscribe

func (*Client) CreateWebhook

func (mg *Client) CreateWebhook(ctx context.Context, domain, id string, urls []string) error

CreateWebhook installs a new webhook for your domain.

func (*Client) DeactivateDomainKey added in v5.10.0

func (mg *Client) DeactivateDomainKey(ctx context.Context, domain, dkimSelector string) error

DeactivateDomainKey deactivates a domain key for the given domain

func (*Client) DeleteAPIKey added in v5.5.0

func (mg *Client) DeleteAPIKey(ctx context.Context, id string) error

func (*Client) DeleteAlert added in v5.3.0

func (mg *Client) DeleteAlert(ctx context.Context, id uuid.UUID) error

func (*Client) DeleteBounce

func (mg *Client) DeleteBounce(ctx context.Context, domain, address string) error

DeleteBounce removes all bounces associated with the provided e-mail address.

func (*Client) DeleteBounceList

func (mg *Client) DeleteBounceList(ctx context.Context, domain string) error

DeleteBounceList removes all bounces in the bounce list

func (*Client) DeleteComplaint

func (mg *Client) DeleteComplaint(ctx context.Context, domain, address string) error

DeleteComplaint removes a previously registered e-mail address from the list of people who complained of receiving spam from your domain.

func (*Client) DeleteCredential

func (mg *Client) DeleteCredential(ctx context.Context, domain, login string) error

DeleteCredential attempts to remove the indicated principle from the domain.

func (*Client) DeleteDomain

func (mg *Client) DeleteDomain(ctx context.Context, domain string) error

DeleteDomain instructs Mailgun to dispose of the named domain name

func (*Client) DeleteDomainIP

func (mg *Client) DeleteDomainIP(ctx context.Context, domain, ip string) error

DeleteDomainIP unassign an IP from the domain specified.

func (*Client) DeleteDomainKey added in v5.10.0

func (mg *Client) DeleteDomainKey(ctx context.Context, domain, dkimSelector string) error

DeleteDomainKey deletes a domain key from the given domain

func (*Client) DeleteIPWarmup added in v5.8.0

func (mg *Client) DeleteIPWarmup(ctx context.Context, ip string) error

func (*Client) DeleteMailingList

func (mg *Client) DeleteMailingList(ctx context.Context, address string) error

DeleteMailingList removes all current members of the list, then removes the list itself. Attempts to send e-mail to the list will fail subsequent to this call.

func (*Client) DeleteMember

func (mg *Client) DeleteMember(ctx context.Context, memberAddress, listAddress string) error

DeleteMember removes the member from the list.

func (*Client) DeleteMonitoredDomain added in v5.4.0

func (mg *Client) DeleteMonitoredDomain(ctx context.Context, opts mtypes.DeleteMonitoredDomainOptions,
) error

DeleteMonitoredDomain deletes a single domain from an account

func (*Client) DeleteRoute

func (mg *Client) DeleteRoute(ctx context.Context, id string) error

DeleteRoute removes the specified route from your domain's configuration. To avoid ambiguity, Mailgun identifies the route by unique ID. See the Route structure definition and the Mailgun API documentation for more details.

func (*Client) DeleteTag

func (mg *Client) DeleteTag(ctx context.Context, domain, tag string) error

DeleteTag removes all counters for a particular tag, including the tag itself.

func (*Client) DeleteTemplate

func (mg *Client) DeleteTemplate(ctx context.Context, domain, name string) error

Delete a template given a template name

func (*Client) DeleteTemplateVersion

func (mg *Client) DeleteTemplateVersion(ctx context.Context, domain, templateName, tag string) error

Delete a specific version of a template

func (*Client) DeleteUnsubscribe

func (mg *Client) DeleteUnsubscribe(ctx context.Context, domain, address string) error

DeleteUnsubscribe removes the e-mail address given from the domain's unsubscription table. If passing in an ID (discoverable from, e.g., ListUnsubscribes()), the e-mail address associated with the given ID will be removed.

func (*Client) DeleteUnsubscribeWithTag

func (mg *Client) DeleteUnsubscribeWithTag(ctx context.Context, domain, address, tag string) error

DeleteUnsubscribeWithTag removes the e-mail address given from the domain's unsubscription table with a matching tag. If passing in an ID (discoverable from, e.g., ListUnsubscribes()), the e-mail address associated with the given ID will be removed.

func (*Client) DeleteWebhook

func (mg *Client) DeleteWebhook(ctx context.Context, domain, name string) error

DeleteWebhook removes the specified webhook from your domain's configuration.

func (*Client) DisableSubaccount

func (mg *Client) DisableSubaccount(ctx context.Context, subaccountId string) (mtypes.SubaccountResponse, error)

DisableSubaccount instructs Mailgun to disable subaccount.

func (*Client) EnableSubaccount

func (mg *Client) EnableSubaccount(ctx context.Context, subaccountId string) (mtypes.SubaccountResponse, error)

EnableSubaccount instructs Mailgun to enable subaccount.

func (*Client) GetBounce

func (mg *Client) GetBounce(ctx context.Context, domain, address string) (mtypes.Bounce, error)

GetBounce retrieves a single bounce record, if any exist, for the given recipient address.

func (*Client) GetComplaint

func (mg *Client) GetComplaint(ctx context.Context, domain, address string) (mtypes.Complaint, error)

GetComplaint returns a single complaint record filed by a recipient at the email address provided. If no complaint exists, the Complaint instance returned will be empty.

func (*Client) GetDomain

func (mg *Client) GetDomain(ctx context.Context, domain string, opts *GetDomainOptions) (mtypes.GetDomainResponse, error)

GetDomain retrieves detailed information about the named domain. https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/domains/get-v4-domains--name-

func (*Client) GetDomainConnection deprecated

func (mg *Client) GetDomainConnection(ctx context.Context, domain string) (mtypes.DomainConnection, error)

GetDomainConnection returns delivery connection settings for the defined domain

Deprecated: use GetDomain instead

TODO(v6): remove

func (*Client) GetDomainTracking

func (mg *Client) GetDomainTracking(ctx context.Context, domain string) (mtypes.DomainTracking, error)

GetDomainTracking returns tracking settings for a domain

func (*Client) GetExport

func (mg *Client) GetExport(ctx context.Context, id string) (mtypes.Export, error)

GetExport gets an export by id

func (mg *Client) GetExportLink(ctx context.Context, id string) (string, error)

Download an export by ID. This will respond with a '302 Moved' with the Location header of temporary S3 URL if it is available.

func (*Client) GetIP

func (mg *Client) GetIP(ctx context.Context, ip string) (mtypes.IPAddress, error)

GetIP returns information about the specified IP

func (*Client) GetIPWarmup added in v5.8.0

func (mg *Client) GetIPWarmup(ctx context.Context, ip string) (mtypes.IPWarmupDetails, error)

GetIPWarmup retrieves the details of a warmup in progress for the specified IP address

func (*Client) GetMailingList

func (mg *Client) GetMailingList(ctx context.Context, address string) (mtypes.MailingList, error)

GetMailingList allows your application to recover the complete List structure representing a mailing list, so long as you have its e-mail address. TODO(v6): rename to GetMailingListByAddress to be more explicit.

func (*Client) GetMember

func (mg *Client) GetMember(ctx context.Context, memberAddress, listAddress string) (mtypes.Member, error)

GetMember returns a complete Member structure for a member of a mailing list, given only their subscription e-mail address.

func (*Client) GetRoute

func (mg *Client) GetRoute(ctx context.Context, id string) (mtypes.Route, error)

GetRoute retrieves the complete route definition associated with the unique route ID.

func (*Client) GetStoredAttachment

func (mg *Client) GetStoredAttachment(ctx context.Context, url string) ([]byte, error)

GetStoredAttachment retrieves the raw MIME body of a received e-mail message attachment.

func (*Client) GetStoredMessage

func (mg *Client) GetStoredMessage(ctx context.Context, url string) (mtypes.StoredMessage, error)

GetStoredMessage retrieves information about a received e-mail message. This provides visibility into, e.g., replies to a message sent to a mailing list.

func (*Client) GetStoredMessageRaw

func (mg *Client) GetStoredMessageRaw(ctx context.Context, url string) (mtypes.StoredMessageRaw, error)

GetStoredMessageRaw retrieves the raw MIME body of a received e-mail message. Compared to GetStoredMessage, it gives access to the unparsed MIME body, and thus delegates to the caller the required parsing.

func (*Client) GetSubaccount

func (mg *Client) GetSubaccount(ctx context.Context, subaccountID string) (mtypes.SubaccountResponse, error)

GetSubaccount retrieves detailed information about subaccount using subaccountID.

func (*Client) GetTag

func (mg *Client) GetTag(ctx context.Context, domain, tag string) (mtypes.Tag, error)

GetTag retrieves metadata about the tag from the api

func (*Client) GetTagLimits

func (mg *Client) GetTagLimits(ctx context.Context, domain string) (mtypes.TagLimits, error)

GetTagLimits returns tracking settings for a domain

func (*Client) GetTemplate

func (mg *Client) GetTemplate(ctx context.Context, domain, name string) (mtypes.Template, error)

GetTemplate gets a template given the template name

func (*Client) GetTemplateVersion

func (mg *Client) GetTemplateVersion(ctx context.Context, domain, templateName, tag string) (mtypes.TemplateVersion, error)

GetTemplateVersion gets a specific version of a template

func (*Client) GetUnsubscribe

func (mg *Client) GetUnsubscribe(ctx context.Context, domain, address string) (mtypes.Unsubscribe, error)

GetUnsubscribe retrieves a single unsubscribe record. Can be used to check if a given address is present in the list of unsubscribed users.

func (*Client) GetWebhook

func (mg *Client) GetWebhook(ctx context.Context, domain, name string) ([]string, error)

GetWebhook retrieves the currently assigned webhook URL associated with the provided type of webhook.

func (*Client) HTTPClient

func (mg *Client) HTTPClient() *http.Client

HTTPClient returns the HTTP client configured for this client.

func (*Client) ListAPIKeys added in v5.5.0

func (mg *Client) ListAPIKeys(ctx context.Context, opts *ListAPIKeysOptions) ([]mtypes.APIKey, error)

func (*Client) ListAlerts added in v5.3.0

ListAlerts returns a list of all configured alert settings for your account.

func (*Client) ListAlertsEvents added in v5.3.0

func (mg *Client) ListAlertsEvents(ctx context.Context, _ *ListAlertsEventsOptions,
) (*mtypes.AlertsEventsResponse, error)

ListAlertsEvents list of events that you can choose to receive alerts for.

func (*Client) ListAllDomainsKeys added in v5.10.0

func (mg *Client) ListAllDomainsKeys(opts *ListAllDomainsKeysOptions) *AllDomainsKeysIterator

ListAllDomainsKeys retrieves a set of domain keys from Mailgun. https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/domain-keys/get-v1-dkim-keys

func (*Client) ListBounces

func (mg *Client) ListBounces(domain string, opts *ListOptions) *BouncesIterator

ListBounces returns a complete set of bounces logged against the sender's domain, if any. The results include the total number of bounces (regardless of skip or limit settings), and the slice of bounces specified, if successful. Note that the length of the slice may be smaller than the total number of bounces.

func (*Client) ListComplaints

func (mg *Client) ListComplaints(domain string, opts *ListOptions) *ComplaintsIterator

ListComplaints returns a set of spam complaints registered against your domain. Recipients of your messages can click on a link which sends feedback to Mailgun indicating that the message they received is, to them, spam.

func (*Client) ListCredentials

func (mg *Client) ListCredentials(domain string, opts *ListOptions) *CredentialsIterator

ListCredentials returns the (possibly zero-length) list of credentials associated with your domain.

func (*Client) ListDomainIPs

func (mg *Client) ListDomainIPs(ctx context.Context, domain string) ([]mtypes.IPAddress, error)

ListDomainIPs returns a list of IPs currently assigned to the specified domain.

func (*Client) ListDomainKeys added in v5.10.0

func (mg *Client) ListDomainKeys(domain string) *DomainKeysIterator

ListDomainKeys retrieves a set of domain keys from Mailgun. https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/domain-keys/get-v4-domains--authority-name--keys

func (*Client) ListDomains

func (mg *Client) ListDomains(opts *ListDomainsOptions) *DomainsIterator

ListDomains retrieves a set of domains from Mailgun. https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/domains/get-v4-domains

func (*Client) ListEvents

func (mg *Client) ListEvents(domain string, opts *ListEventOptions) *EventIterator

ListEvents creates a new iterator to fetch a page of events from the events api

func (*Client) ListExports

func (mg *Client) ListExports(ctx context.Context, url string) ([]mtypes.Export, error)

ListExports lists all exports created within the past 24 hours

func (*Client) ListIPDomains added in v5.2.0

func (mg *Client) ListIPDomains(ip string, opts *ListIPDomainOptions) *IPDomainsIterator

ListIPDomains retrieves a list of domains for the specified IP address.

func (*Client) ListIPWarmups added in v5.8.0

func (mg *Client) ListIPWarmups() *IPWarmupsIterator

ListIPWarmups retrieves a list of warmups in progress in the account

func (*Client) ListIPs

func (mg *Client) ListIPs(ctx context.Context, dedicated, enabled bool) ([]mtypes.IPAddress, error)

ListIPs returns a list of IPs assigned to your account, including their warmup and assignable to pools status if applicable.

func (*Client) ListMailingLists

func (mg *Client) ListMailingLists(opts *ListOptions) *ListsIterator

ListMailingLists returns the specified set of mailing lists administered by your account.

func (*Client) ListMembers

func (mg *Client) ListMembers(listAddress string, opts *ListOptions) *MemberListIterator

func (*Client) ListMetrics

func (mg *Client) ListMetrics(opts MetricsOptions) (*MetricsIterator, error)

ListMetrics returns domain/account metrics.

To filter by domain:

opts.Filter.BoolGroupAnd = []mailgun.MetricsFilterPredicate{{
	Attribute:     "domain",
	Comparator:    "=",
	LabeledValues: []mailgun.MetricsLabeledValue{{Label: "example.com", Value: "example.com"}},
}}

https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Metrics/

func (*Client) ListMonitoredDomains added in v5.4.0

func (mg *Client) ListMonitoredDomains(opts ListMonitoredDomainsOptions) (*MonitoredDomainsIterator, error)

func (*Client) ListRoutes

func (mg *Client) ListRoutes(opts *ListOptions) *RoutesIterator

ListRoutes allows you to iterate through a list of routes returned by the API

func (*Client) ListSubaccounts

func (mg *Client) ListSubaccounts(opts *ListSubaccountsOptions) *SubaccountsIterator

ListSubaccounts retrieves a set of subaccount linked to the primary Mailgun account.

func (*Client) ListTags

func (mg *Client) ListTags(domain string, opts *ListTagOptions) *TagIterator

ListTags returns a cursor used to iterate through a list of tags

it := mg.ListTags(nil)
var page []mailgun.Tag
for it.Next(&page) {
	for _, tag := range(page) {
		// Do stuff with tags
	}
}
if it.Err() != nil {
	log.Fatal(it.Err())
}

func (*Client) ListTemplateVersions

func (mg *Client) ListTemplateVersions(domain, templateName string, opts *ListOptions) *TemplateVersionsIterator

ListTemplateVersions lists all the versions of a specific template

func (*Client) ListTemplates

func (mg *Client) ListTemplates(domain string, opts *ListTemplateOptions) *TemplatesIterator

List all available templates

func (*Client) ListUnsubscribes

func (mg *Client) ListUnsubscribes(domain string, opts *ListOptions) *UnsubscribesIterator

ListUnsubscribes fetches the list of unsubscribes

func (*Client) ListWebhooks

func (mg *Client) ListWebhooks(ctx context.Context, domain string) (map[string][]string, error)

ListWebhooks returns the complete set of webhooks configured for your domain. Note that a zero-length mapping is not an error.

func (*Client) PollEvents

func (mg *Client) PollEvents(domain string, opts *ListEventOptions) *EventPoller

PollEvents polls the events api and return new events as they occur

it = mg.PollEvents("example.com", &ListEventOptions{
	// Only events with a timestamp after this date/time will be returned
	Begin:        time.Now().Add(time.Second * -3),
	// How often we poll the api for new events
	PollInterval: time.Second * 4
})

var events []Event
ctx, cancel := context.WithCancel(context.Background())

// Blocks until new events appear or context is cancelled
for it.Poll(ctx, &events) {
	for _, event := range(events) {
		fmt.Printf("Event %+v\n", event)
	}
}
if it.Err() != nil {
	log.Fatal(it.Err())
}

func (*Client) ReSend

func (mg *Client) ReSend(ctx context.Context, url string, recipients ...string) (mtypes.SendMessageResponse, error)

ReSend given a storage url resend the stored message to the specified recipients

func (*Client) RegeneratePublicAPIKey added in v5.5.0

func (mg *Client) RegeneratePublicAPIKey(ctx context.Context) (mtypes.RegeneratePublicAPIKeyResponse, error)

func (*Client) RemoveOnBehalfOfSubaccount

func (mg *Client) RemoveOnBehalfOfSubaccount()

RemoveOnBehalfOfSubaccount remove X-Mailgun-On-Behalf-Of header for primary usage.

func (*Client) Send

Send attempts to queue a message (see PlainMessage, MimeMessage and its methods) for delivery. It returns the Mailgun server response, which consists of two components:

  • A human-readable status message, typically "Queued. Thank you."
  • A Message ID, which is the id used to track the queued message. The message id is useful when contacting support to report an issue with a specific message or to relate a delivered, accepted or failed event back to a specific message.

The status and message ID are only returned if no error occurred.

Returned error can be wrapped internal and standard Go errors like `url.Error`. The error can also be of type mailgun.UnexpectedResponseError which contains the error returned by the mailgun API.

See the public mailgun documentation for all possible return codes and error messages

func (*Client) SetAPIBase

func (mg *Client) SetAPIBase(address string) error

SetAPIBase updates the API Base URL for this client.

// For EU Customers
mg.SetAPIBase(mailgun.APIBaseEU)

// For US Customers
mg.SetAPIBase(mailgun.APIBaseUS)

// Set a custom base API
mg.SetAPIBase("https://localhost")

func (*Client) SetHTTPClient

func (mg *Client) SetHTTPClient(c *http.Client)

SetHTTPClient updates the HTTP client for this client.

func (*Client) SetOnBehalfOfSubaccount

func (mg *Client) SetOnBehalfOfSubaccount(subaccountId string)

SetOnBehalfOfSubaccount sets X-Mailgun-On-Behalf-Of header to SUBACCOUNT_ACCOUNT_ID in order to perform API request on behalf of subaccount.

func (*Client) SetWebhookSigningKey

func (mg *Client) SetWebhookSigningKey(webhookSigningKey string)

SetWebhookSigningKey updates the webhook signing key for this client

func (*Client) UpdateClickTracking

func (mg *Client) UpdateClickTracking(ctx context.Context, domain, active string) error

func (*Client) UpdateDomain

func (mg *Client) UpdateDomain(ctx context.Context, domain string, opts *UpdateDomainOptions) error

UpdateDomain updates a domain's attributes.

func (*Client) UpdateDomainConnection deprecated

func (mg *Client) UpdateDomainConnection(ctx context.Context, domain string, settings mtypes.DomainConnection) error

UpdateDomainConnection updates the specified delivery connection settings for the defined domain

Deprecated: use UpdateDomain instead

TODO(v6): remove

func (*Client) UpdateDomainDkimAuthority added in v5.10.0

func (mg *Client) UpdateDomainDkimAuthority(ctx context.Context, domain string, self bool) (mtypes.UpdateDomainDkimAuthorityResponse, error)

func (*Client) UpdateDomainDkimSelector

func (mg *Client) UpdateDomainDkimSelector(ctx context.Context, domain, dkimSelector string) error

UpdateDomainDkimSelector updates the DKIM selector for a domain

func (*Client) UpdateMailingList

func (mg *Client) UpdateMailingList(ctx context.Context, address string, list mtypes.MailingList) (mtypes.MailingList, error)

UpdateMailingList allows you to change various attributes of a list. Address, Name, Description, AccessLevel and ReplyPreference are all optional; only those fields which are set in the prototype will change.

Be careful! If changing the address of a mailing list, e-mail sent to the old address will not succeed. Make sure you account for the change accordingly.

func (*Client) UpdateMember

func (mg *Client) UpdateMember(ctx context.Context, memberAddress, listAddress string, member mtypes.Member) (mtypes.Member, error)

UpdateMember lets you change certain details about the indicated mailing list member. Address, Name, Vars, and Subscribed fields may be changed.

func (*Client) UpdateOpenTracking

func (mg *Client) UpdateOpenTracking(ctx context.Context, domain, active string) error

func (*Client) UpdateRoute

func (mg *Client) UpdateRoute(ctx context.Context, id string, route mtypes.Route) (mtypes.Route, error)

UpdateRoute provides an "in-place" update of the specified route. Only those route fields which are non-zero or non-empty are updated. All other fields remain as-is.

func (*Client) UpdateTemplate

func (mg *Client) UpdateTemplate(ctx context.Context, domain string, template *mtypes.Template) error

Update the name and description of a template

func (*Client) UpdateTemplateVersion

func (mg *Client) UpdateTemplateVersion(ctx context.Context, domain, templateName string, version *mtypes.TemplateVersion) error

Update the comment and mark a version of a template active

func (*Client) UpdateUnsubscribeTracking

func (mg *Client) UpdateUnsubscribeTracking(ctx context.Context, domain, active, htmlFooter, textFooter string) error

func (*Client) UpdateWebhook

func (mg *Client) UpdateWebhook(ctx context.Context, domain, name string, urls []string) error

UpdateWebhook replaces one webhook setting for another.

func (*Client) ValidateEmail

func (mg *Client) ValidateEmail(ctx context.Context, email string, mailBoxVerify bool) (mtypes.ValidateEmailResponse, error)

ValidateEmail performs various checks on the email address provided to ensure it's correctly formatted. It may also be used to break an email address into its sub-components. https://documentation.mailgun.com/docs/inboxready/mailgun-validate/single-valid-ir/

func (*Client) VerifyAndReturnDomain deprecated

func (mg *Client) VerifyAndReturnDomain(ctx context.Context, domain string) (mtypes.GetDomainResponse, error)

VerifyAndReturnDomain verifies the domains DNS records (includes A, CNAME, SPF, DKIM and MX records) to ensure the domain is ready and able to send.

Deprecated: use VerifyDomain instead.

TODO(v6): remove this method

func (*Client) VerifyDomain added in v5.4.0

func (mg *Client) VerifyDomain(ctx context.Context, domain string) (mtypes.GetDomainResponse, error)

VerifyDomain verifies the domains DNS records (includes A, CNAME, SPF, DKIM and MX records) to ensure the domain is ready and able to send.

func (*Client) VerifyWebhookSignature

func (mg *Client) VerifyWebhookSignature(sig mtypes.Signature) (verified bool, err error)

VerifyWebhookSignature - use this method to parse the webhook signature given as JSON in the webhook response

func (*Client) WebhookSigningKey

func (mg *Client) WebhookSigningKey() string

WebhookSigningKey returns the webhook signing key configured for this client

type CommonMessage

type CommonMessage struct {
	// contains filtered or unexported fields
}

CommonMessage contains both the message text and the envelope for an e-mail message. TODO(vtopc): create AddOption(key string, value string) for `o:` options?

func (*CommonMessage) AddAttachment

func (m *CommonMessage) AddAttachment(attachment string)

AddAttachment arranges to send a file from the filesystem along with the e-mail message. The attachment parameter is a filename, which must refer to a file which actually resides in the local filesystem.

func (*CommonMessage) AddBufferAttachment

func (m *CommonMessage) AddBufferAttachment(filename string, buffer []byte)

AddBufferAttachment arranges to send a file along with the e-mail message. File contents are read from the []byte array provided The filename parameter is the resulting filename of the attachment. The buffer parameter is the []byte array which contains the actual bytes to be used as the contents of the attached file.

func (*CommonMessage) AddDomain

func (m *CommonMessage) AddDomain(domain string)

AddDomain allows you to use a separate domain for the type of messages you are sending.

func (*CommonMessage) AddHeader

func (m *CommonMessage) AddHeader(header, value string)

AddHeader allows you to send custom MIME headers with the message.

func (*CommonMessage) AddInline

func (m *CommonMessage) AddInline(inline string)

AddInline arranges to send a file along with the e-mail message, but does so in a way that its data remains "inline" with the rest of the message. This can be used to send image or font data along with an HTML-encoded message body. The attachment parameter is a filename, which must refer to a file which actually resides in the local filesystem.

func (*CommonMessage) AddReaderAttachment

func (m *CommonMessage) AddReaderAttachment(filename string, readCloser io.ReadCloser)

AddReaderAttachment arranges to send a file along with the e-mail message. File contents are read from an io.ReadCloser. The filename parameter is the resulting filename of the attachment. The readCloser parameter is the io.ReadCloser that reads the actual bytes to be used as the contents of the attached file.

func (*CommonMessage) AddReaderInline

func (m *CommonMessage) AddReaderInline(filename string, readCloser io.ReadCloser)

AddReaderInline arranges to send a file along with the e-mail message. File contents are read from an io.ReadCloser. The filename parameter is the resulting filename of the attachment. The readCloser parameter is the io.ReadCloser that reads the actual bytes to be used as the contents of the attached file.

func (*CommonMessage) AddTag

func (m *CommonMessage) AddTag(tag ...string) error

AddTag attaches tags to the message. Tags are useful for metrics gathering and event tracking purposes. Refer to the Mailgun documentation for further details.

func (*CommonMessage) AddTemplateVariable

func (m *CommonMessage) AddTemplateVariable(variable string, value any) error

AddTemplateVariable adds a template variable to the map of template variables, replacing the variable if it is already there. This is used for server-side message templates and can nest arbitrary values. At send time, the resulting map will be converted into a JSON string and sent as a header in the X-Mailgun-Variables header.

func (*CommonMessage) AddVariable

func (m *CommonMessage) AddVariable(variable string, value any) error

AddVariable lets you associate a set of variables with messages you send, which Mailgun can use to, in essence, complete form-mail. Refer to the Mailgun documentation for more information.

func (*CommonMessage) Attachments

func (m *CommonMessage) Attachments() []string

func (*CommonMessage) BufferAttachments

func (m *CommonMessage) BufferAttachments() []BufferAttachment

func (*CommonMessage) DKIM

func (m *CommonMessage) DKIM() *bool

func (*CommonMessage) DeliveryTime

func (m *CommonMessage) DeliveryTime() time.Time

func (*CommonMessage) Domain

func (m *CommonMessage) Domain() string

func (*CommonMessage) EnableNativeSend

func (m *CommonMessage) EnableNativeSend()

EnableNativeSend allows the return path to match the address in the CommonMessage.Headers.From: field when sending from Mailgun rather than the usual bounce+ address in the return path.

func (*CommonMessage) EnableTestMode

func (m *CommonMessage) EnableTestMode()

EnableTestMode allows submittal of a message, such that it will be discarded by Mailgun. This facilitates testing client-side software without actually consuming e-mail resources.

func (*CommonMessage) Headers

func (m *CommonMessage) Headers() map[string]string

Headers retrieve the http headers associated with this message

func (*CommonMessage) Inlines

func (m *CommonMessage) Inlines() []string

func (*CommonMessage) NativeSend

func (m *CommonMessage) NativeSend() bool

func (*CommonMessage) ReaderAttachments

func (m *CommonMessage) ReaderAttachments() []ReaderAttachment

func (*CommonMessage) ReaderInlines

func (m *CommonMessage) ReaderInlines() []ReaderAttachment

func (*CommonMessage) RecipientVariables

func (m *CommonMessage) RecipientVariables() map[string]map[string]any

func (*CommonMessage) RequireTLS

func (m *CommonMessage) RequireTLS() bool

func (*CommonMessage) STOPeriod

func (m *CommonMessage) STOPeriod() string

func (*CommonMessage) SecondaryDKIM added in v5.10.0

func (m *CommonMessage) SecondaryDKIM() string

func (*CommonMessage) SecondaryDKIMPublic added in v5.10.0

func (m *CommonMessage) SecondaryDKIMPublic() string

func (*CommonMessage) SetDKIM

func (m *CommonMessage) SetDKIM(dkim bool)

SetDKIM arranges to send the o:dkim header with the message, and sets its value accordingly. Refer to the Mailgun documentation for more information.

func (*CommonMessage) SetDeliveryTime

func (m *CommonMessage) SetDeliveryTime(dt time.Time)

SetDeliveryTime schedules the message for transmission at the indicated time. Pass nil to remove any installed schedule. Refer to the Mailgun documentation for more information.

func (*CommonMessage) SetReplyTo

func (m *CommonMessage) SetReplyTo(recipient string)

SetReplyTo sets the receiver who should receive replies

func (*CommonMessage) SetRequireTLS

func (m *CommonMessage) SetRequireTLS(b bool)

SetRequireTLS information is found in the Mailgun documentation.

func (*CommonMessage) SetSTOPeriod

func (m *CommonMessage) SetSTOPeriod(stoPeriod string) error

SetSTOPeriod toggles Send Time Optimization (STO) on a per-message basis. String should be set to the number of hours in [0-9]+h format, with the minimum being 24h and the maximum being 72h. Refer to the Mailgun documentation for more information.

func (*CommonMessage) SetSecondaryDKIM added in v5.10.0

func (m *CommonMessage) SetSecondaryDKIM(s string)

SetSecondaryDKIM specifies a second domain key to sign the email with. The value is formatted as signing_domain/selector, e.g. example.com/s1.

func (*CommonMessage) SetSecondaryDKIMPublic added in v5.10.0

func (m *CommonMessage) SetSecondaryDKIMPublic(s string)

SetSecondaryDKIMPublic specifies an alias of the domain key specified in o:secondary-dkim. Also formatted as public_signing_domain/selector. o:secondary-dkim option must also be provided.

func (*CommonMessage) SetSkipVerification

func (m *CommonMessage) SetSkipVerification(b bool)

SetSkipVerification information is found in the Mailgun documentation.

func (*CommonMessage) SetTemplateRenderText

func (m *CommonMessage) SetTemplateRenderText(render bool)

SetTemplateRenderText information is found in the Mailgun documentation.

func (*CommonMessage) SetTemplateVersion

func (m *CommonMessage) SetTemplateVersion(tag string)

SetTemplateVersion information is found in the Mailgun documentation.

func (*CommonMessage) SetTracking

func (m *CommonMessage) SetTracking(tracking bool)

SetTracking sets the o:tracking message parameter to adjust, on a message-by-message basis, whether or not Mailgun will rewrite URLs to facilitate event tracking. Events tracked includes opens, clicks, unsubscribes, etc. Note: simply calling this method ensures that the o:tracking header is passed in with the message. Its yes/no setting is determined by the call's parameter. Note that this header is not passed on to the final recipient(s). Refer to the Mailgun documentation for more information.

func (*CommonMessage) SetTrackingClicks

func (m *CommonMessage) SetTrackingClicks(trackingClicks bool)

SetTrackingClicks information is found in the Mailgun documentation.

func (*CommonMessage) SetTrackingOpens

func (m *CommonMessage) SetTrackingOpens(trackingOpens bool)

SetTrackingOpens information is found in the Mailgun documentation.

func (*CommonMessage) SetTrackingOptions

func (m *CommonMessage) SetTrackingOptions(options *TrackingOptions)

SetTrackingOptions sets o:tracking, o:tracking-clicks, o:tracking-pixel-location-top, and o:tracking-opens at once.

func (*CommonMessage) SkipVerification

func (m *CommonMessage) SkipVerification() bool

func (*CommonMessage) Tags

func (m *CommonMessage) Tags() []string

func (*CommonMessage) TemplateRenderText

func (m *CommonMessage) TemplateRenderText() bool

func (*CommonMessage) TemplateVariables

func (m *CommonMessage) TemplateVariables() map[string]any

func (*CommonMessage) TemplateVersionTag

func (m *CommonMessage) TemplateVersionTag() string

func (*CommonMessage) TestMode

func (m *CommonMessage) TestMode() bool

func (*CommonMessage) To

func (m *CommonMessage) To() []string

func (*CommonMessage) Tracking

func (m *CommonMessage) Tracking() *bool

func (*CommonMessage) TrackingClicks

func (m *CommonMessage) TrackingClicks() *string

func (*CommonMessage) TrackingOpens

func (m *CommonMessage) TrackingOpens() *bool

func (*CommonMessage) TrackingPixelLocationTop added in v5.3.0

func (m *CommonMessage) TrackingPixelLocationTop() *string

func (*CommonMessage) Variables

func (m *CommonMessage) Variables() map[string]string

type ComplaintsIterator

type ComplaintsIterator struct {
	mtypes.ComplaintsResponse
	// contains filtered or unexported fields
}

func (*ComplaintsIterator) Err

func (ci *ComplaintsIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*ComplaintsIterator) First

func (ci *ComplaintsIterator) First(ctx context.Context, items *[]mtypes.Complaint) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*ComplaintsIterator) Last

func (ci *ComplaintsIterator) Last(ctx context.Context, items *[]mtypes.Complaint) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*ComplaintsIterator) Next

func (ci *ComplaintsIterator) Next(ctx context.Context, items *[]mtypes.Complaint) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*ComplaintsIterator) Previous

func (ci *ComplaintsIterator) Previous(ctx context.Context, items *[]mtypes.Complaint) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type CreateAPIKeyOptions added in v5.5.0

type CreateAPIKeyOptions struct {
	Description string
	DomainName  string
	Email       string
	Expiration  uint64 // The key's lifetime in seconds.
	Kind        string
	UserID      string
	UserName    string
}

type CreateDomainKeyOptions added in v5.10.0

type CreateDomainKeyOptions struct {
	Bits int
	PEM  string
}

type CreateDomainOptions

type CreateDomainOptions struct {
	Password                   string
	SpamAction                 mtypes.SpamAction
	Wildcard                   bool
	ForceDKIMAuthority         bool
	DKIMKeySize                int
	IPs                        []string
	WebScheme                  string
	UseAutomaticSenderSecurity bool
	ArchiveTo                  string
	DKIMHostName               string
	DKIMSelector               string
	ForceRootDKIMHost          bool
	EncryptIncomingMessage     bool
	PoolID                     string
	RequireTLS                 bool
	SkipVerification           bool
	WebPrefix                  string
	MessageTTL                 int
}

CreateDomainOptions - optional parameters when creating a domain https://documentation.mailgun.com/docs/mailgun/api-reference/openapi-final/tag/Domains/#tag/Domains/operation/POST-v4-domains

type CredentialsIterator

type CredentialsIterator struct {
	mtypes.CredentialsListResponse
	// contains filtered or unexported fields
}

func (*CredentialsIterator) Err

func (ri *CredentialsIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*CredentialsIterator) First

func (ri *CredentialsIterator) First(ctx context.Context, items *[]mtypes.Credential) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*CredentialsIterator) Last

func (ri *CredentialsIterator) Last(ctx context.Context, items *[]mtypes.Credential) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*CredentialsIterator) Next

func (ri *CredentialsIterator) Next(ctx context.Context, items *[]mtypes.Credential) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*CredentialsIterator) Offset

func (ri *CredentialsIterator) Offset() int

Offset returns the current offset of the iterator

func (*CredentialsIterator) Previous

func (ri *CredentialsIterator) Previous(ctx context.Context, items *[]mtypes.Credential) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type DomainKeysIterator added in v5.10.0

type DomainKeysIterator struct {
	mtypes.ListDomainKeysResponse
	// contains filtered or unexported fields
}

DomainKeysIterator is a list iterator for https://documentation.mailgun.com/docs/mailgun/api-reference/send/mailgun/domain-keys/get-v4-domains--authority-name--keys

TODO(vtopc): implement paging methods: Last and Previous when API will return paging object.

func (*DomainKeysIterator) Err added in v5.10.0

func (iter *DomainKeysIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*DomainKeysIterator) First added in v5.10.0

func (iter *DomainKeysIterator) First(ctx context.Context, items *[]mtypes.DomainKey) bool

First retrieves the first page of items from the API. Returns false if there was an error. Use `.Err()` to retrieve the error.

func (*DomainKeysIterator) Last added in v5.10.0

func (iter *DomainKeysIterator) Last(_ context.Context, _ *[]mtypes.DomainKey) bool

Last - not implemented on API. Use Next() instead.

func (*DomainKeysIterator) Next added in v5.10.0

func (iter *DomainKeysIterator) Next(ctx context.Context, items *[]mtypes.DomainKey) bool

Next retrieves the next(or first) page of items from the API. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error.

func (*DomainKeysIterator) Previous added in v5.10.0

func (iter *DomainKeysIterator) Previous(_ context.Context, _ *[]mtypes.DomainKey) bool

Previous - not implemented on API. Use Next() instead.

type DomainsIterator

type DomainsIterator struct {
	mtypes.ListDomainsResponse
	// contains filtered or unexported fields
}

func (*DomainsIterator) Err

func (ri *DomainsIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*DomainsIterator) First

func (ri *DomainsIterator) First(ctx context.Context, items *[]mtypes.Domain) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*DomainsIterator) Last

func (ri *DomainsIterator) Last(ctx context.Context, items *[]mtypes.Domain) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*DomainsIterator) Next

func (ri *DomainsIterator) Next(ctx context.Context, items *[]mtypes.Domain) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*DomainsIterator) Offset

func (ri *DomainsIterator) Offset() int

Offset returns the current offset of the iterator

func (*DomainsIterator) Previous

func (ri *DomainsIterator) Previous(ctx context.Context, items *[]mtypes.Domain) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type EventIterator

type EventIterator struct {
	events.Response
	// contains filtered or unexported fields
}

EventIterator maintains the state necessary for paging though small parcels of a larger set of events.

func (*EventIterator) Err

func (ei *EventIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*EventIterator) First

func (ei *EventIterator) First(ctx context.Context, ee *[]events.Event) bool

First retrieves the first page of events from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*EventIterator) Last

func (ei *EventIterator) Last(ctx context.Context, ee *[]events.Event) bool

Last retrieves the last page of events from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*EventIterator) Next

func (ei *EventIterator) Next(ctx context.Context, ee *[]events.Event) bool

Next retrieves the next page of events from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*EventIterator) Previous

func (ei *EventIterator) Previous(ctx context.Context, ee *[]events.Event) bool

Previous retrieves the previous page of events from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type EventPoller

type EventPoller struct {
	// contains filtered or unexported fields
}

EventPoller maintains the state necessary for polling events

func (*EventPoller) Err

func (ep *EventPoller) Err() error

If an error occurred during polling `Err()` will return non nil

func (*EventPoller) Poll

func (ep *EventPoller) Poll(ctx context.Context, ee *[]events.Event) bool

type FormDataPayload

type FormDataPayload struct {
	Values      []keyValuePair
	Files       []keyValuePair
	ReadClosers []keyNameRC
	Buffers     []keyNameBuff
	// contains filtered or unexported fields
}

func NewFormDataPayload

func NewFormDataPayload() *FormDataPayload

type ForwardedMessage

type ForwardedMessage struct {
	BodyPlain      string            // body-plain
	From           string            // from
	MessageHeaders map[string]string // message-headers
	Recipient      string            // recipient
	Sender         string            // sender
	Signature      string            // signature
	StrippedHTML   string            // stripped-html
	StrippedText   string            // stripped-text
	Subject        string            // subject
	Timestamp      time.Time         // timestamp
	Token          string            // token
}

ForwardedMessage represents the payload the server will get on match You can use ExtractForwardRoute() to extract PostForm into the struct, or you can use only the struct and parse the form manually

func ExtractForwardedMessage

func ExtractForwardedMessage(formValues url.Values) ForwardedMessage

ExtractForwardedMessage extracts the forward route payload values from a parsed PostForm Example usage:

func Handler(w http.ResponseWriter, r *http.Request) {
err := r.ParseForm()
if err != nil {
	log.Fatal(err)
}
forwardRoute := mailgun.ExtractForwardedMessage(r.PostForm)
fmt.Printf("Forwarded message: %#v", forwardRoute)
}

type GetDomainOptions

type GetDomainOptions struct {
	// If set to true, domain payload will include dkim_host, mailfrom_host and pod
	Extended *bool

	// Domain payload will include sending and receiving dns records payload
	WithDNS *bool
}

type IPDomainsIterator added in v5.2.0

type IPDomainsIterator struct {
	mtypes.ListIPDomainsResponse
	// contains filtered or unexported fields
}

func (*IPDomainsIterator) Err added in v5.2.0

func (ri *IPDomainsIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*IPDomainsIterator) First added in v5.2.0

func (ri *IPDomainsIterator) First(ctx context.Context, items *[]mtypes.DomainIPs) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*IPDomainsIterator) Last added in v5.2.0

func (ri *IPDomainsIterator) Last(ctx context.Context, items *[]mtypes.DomainIPs) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*IPDomainsIterator) Next added in v5.2.0

func (ri *IPDomainsIterator) Next(ctx context.Context, items *[]mtypes.DomainIPs) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*IPDomainsIterator) Offset added in v5.2.0

func (ri *IPDomainsIterator) Offset() int

Offset returns the current offset of the iterator

func (*IPDomainsIterator) Previous added in v5.2.0

func (ri *IPDomainsIterator) Previous(ctx context.Context, items *[]mtypes.DomainIPs) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type IPWarmupsIterator added in v5.8.0

type IPWarmupsIterator struct {
	mtypes.ListIPWarmupsResponse
	// contains filtered or unexported fields
}

func (*IPWarmupsIterator) Err added in v5.8.0

func (ri *IPWarmupsIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*IPWarmupsIterator) First added in v5.8.0

func (ri *IPWarmupsIterator) First(ctx context.Context, items *[]mtypes.IPWarmup) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*IPWarmupsIterator) Next added in v5.8.0

func (ri *IPWarmupsIterator) Next(ctx context.Context, items *[]mtypes.IPWarmup) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

type ListAPIKeysOptions added in v5.5.0

type ListAPIKeysOptions struct {
	DomainName string
	Kind       string
}

type ListAlertsEventsOptions added in v5.3.0

type ListAlertsEventsOptions struct{}

type ListAlertsOptions added in v5.3.0

type ListAlertsOptions struct{}

type ListAllDomainsKeysOptions added in v5.10.0

type ListAllDomainsKeysOptions struct {
	Limit int // NOTE: currently ignored by Mailgun API
}

type ListDomainsOptions

type ListDomainsOptions struct {
	Limit int

	// Get only domains with a specific state.
	State *mtypes.DomainState

	// If sorting is not specified domains are returned in reverse creation date order.
	Sort *string

	// Get only domains with a specific authority.
	Authority *string

	// Search domains by the given partial or complete name. Does not support wildcards.
	Search *string

	// Search on every domain that belongs to any subaccounts under this account.
	IncludeSubaccounts *bool
}

type ListEventOptions

type ListEventOptions struct {
	// Limits the results to a specific start and end time
	Begin, End time.Time
	// ForceAscending and ForceDescending are used to force Mailgun to use a given
	// traversal order of the events. If both ForceAscending and ForceDescending are
	// true, an error will result. If none, the default will be inferred from the Begin
	// and End parameters.
	ForceAscending, ForceDescending bool
	// Compact, if true, compacts the returned JSON to minimize transmission bandwidth.
	Compact bool
	// Limit caps the number of results returned.  If left unspecified, MailGun assumes 100.
	Limit int
	// Filter allows the caller to provide more specialized filters on the query.
	// Consult the Mailgun documentation for more details.
	Filter       map[string]string
	PollInterval time.Duration
}

ListEventOptions modifies the behavior of ListEvents()

type ListIPDomainOptions added in v5.2.0

type ListIPDomainOptions struct {
	Limit int
}

type ListMonitoredDomainsOptions added in v5.4.0

type ListMonitoredDomainsOptions = inboxready.GETV1InboxreadyDomainsParams

type ListOptions

type ListOptions struct {
	Limit int
}

ListOptions used by List methods to specify what list parameters to send to the mailgun API

type ListSubaccountsOptions

type ListSubaccountsOptions struct {
	Limit     int
	Skip      int
	SortArray string
	Enabled   bool
}

type ListTagOptions

type ListTagOptions struct {
	// Restrict the page size to this limit
	Limit int
	// Return only the tags starting with the given prefix
	Prefix string
}

type ListTemplateOptions

type ListTemplateOptions struct {
	Limit  int
	Active bool
}

type ListsIterator

type ListsIterator struct {
	mtypes.ListMailingListsResponse
	// contains filtered or unexported fields
}

func (*ListsIterator) Err

func (li *ListsIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*ListsIterator) First

func (li *ListsIterator) First(ctx context.Context, items *[]mtypes.MailingList) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*ListsIterator) Last

func (li *ListsIterator) Last(ctx context.Context, items *[]mtypes.MailingList) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*ListsIterator) Next

func (li *ListsIterator) Next(ctx context.Context, items *[]mtypes.MailingList) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*ListsIterator) Previous

func (li *ListsIterator) Previous(ctx context.Context, items *[]mtypes.MailingList) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type Mailgun

type Mailgun interface {
	APIBase() string
	APIKey() string
	HTTPClient() *http.Client
	SetHTTPClient(client *http.Client)
	SetAPIBase(url string) error
	AddOverrideHeader(k string, v string)

	// Send attempts to queue a message (see CommonMessage, NewMessage, and its methods) for delivery.
	Send(ctx context.Context, m Message) (mtypes.SendMessageResponse, error)
	ReSend(ctx context.Context, url string, recipients ...string) (mtypes.SendMessageResponse, error)

	ListBounces(domain string, opts *ListOptions) *BouncesIterator
	GetBounce(ctx context.Context, domain, address string) (mtypes.Bounce, error)
	AddBounce(ctx context.Context, domain, address, code, err string) error
	DeleteBounce(ctx context.Context, domain, address string) error
	DeleteBounceList(ctx context.Context, domain string) error

	ListMetrics(opts MetricsOptions) (*MetricsIterator, error)

	GetTag(ctx context.Context, domain, tag string) (mtypes.Tag, error)
	DeleteTag(ctx context.Context, domain, tag string) error
	ListTags(domain string, opts *ListTagOptions) *TagIterator

	ListDomains(opts *ListDomainsOptions) *DomainsIterator
	GetDomain(ctx context.Context, domain string, opts *GetDomainOptions) (mtypes.GetDomainResponse, error)
	CreateDomain(ctx context.Context, domain string, opts *CreateDomainOptions) (mtypes.GetDomainResponse, error)
	VerifyDomain(ctx context.Context, domain string) (mtypes.GetDomainResponse, error)
	UpdateDomain(ctx context.Context, domain string, opts *UpdateDomainOptions) error
	DeleteDomain(ctx context.Context, domain string) error
	// Deprecated: use VerifyDomain instead.
	VerifyAndReturnDomain(ctx context.Context, domain string) (mtypes.GetDomainResponse, error)
	ListIPDomains(ip string, opts *ListIPDomainOptions) *IPDomainsIterator

	// Deprecated: use UpdateDomain instead
	UpdateDomainConnection(ctx context.Context, domain string, dc mtypes.DomainConnection) error
	// Deprecated: use GetDomain instead
	GetDomainConnection(ctx context.Context, domain string) (mtypes.DomainConnection, error)

	GetDomainTracking(ctx context.Context, domain string) (mtypes.DomainTracking, error)
	UpdateClickTracking(ctx context.Context, domain, active string) error
	UpdateUnsubscribeTracking(ctx context.Context, domain, active, htmlFooter, textFooter string) error
	UpdateOpenTracking(ctx context.Context, domain, active string) error

	ListAllDomainsKeys(opts *ListAllDomainsKeysOptions) *AllDomainsKeysIterator
	CreateDomainKey(ctx context.Context, domain, dkimSelector string, opts *CreateDomainKeyOptions) (mtypes.DomainKey, error)
	DeleteDomainKey(ctx context.Context, domain, dkimSelector string) error
	ActivateDomainKey(ctx context.Context, domain, dkimSelector string) error
	ListDomainKeys(domain string) *DomainKeysIterator
	DeactivateDomainKey(ctx context.Context, domain, dkimSelector string) error
	UpdateDomainDkimAuthority(ctx context.Context, domain string, self bool) (mtypes.UpdateDomainDkimAuthorityResponse, error)
	UpdateDomainDkimSelector(ctx context.Context, domain, dkimSelector string) error

	GetStoredMessage(ctx context.Context, url string) (mtypes.StoredMessage, error)
	GetStoredMessageRaw(ctx context.Context, id string) (mtypes.StoredMessageRaw, error)
	GetStoredAttachment(ctx context.Context, url string) ([]byte, error)

	ListCredentials(domain string, opts *ListOptions) *CredentialsIterator
	CreateCredential(ctx context.Context, domain, login, password string) error
	ChangeCredentialPassword(ctx context.Context, domain, login, password string) error
	DeleteCredential(ctx context.Context, domain, login string) error

	ListUnsubscribes(domain string, opts *ListOptions) *UnsubscribesIterator
	GetUnsubscribe(ctx context.Context, domain, address string) (mtypes.Unsubscribe, error)
	CreateUnsubscribe(ctx context.Context, domain, address, tag string) error
	CreateUnsubscribes(ctx context.Context, domain string, unsubscribes []mtypes.Unsubscribe) error
	DeleteUnsubscribe(ctx context.Context, domain, address string) error
	DeleteUnsubscribeWithTag(ctx context.Context, domain, address, tag string) error

	ListComplaints(domain string, opts *ListOptions) *ComplaintsIterator
	GetComplaint(ctx context.Context, domain, address string) (mtypes.Complaint, error)
	CreateComplaint(ctx context.Context, domain, address string) error
	CreateComplaints(ctx context.Context, domain string, addresses []string) error
	DeleteComplaint(ctx context.Context, domain, address string) error

	ListRoutes(opts *ListOptions) *RoutesIterator
	GetRoute(ctx context.Context, id string) (mtypes.Route, error)
	CreateRoute(ctx context.Context, route mtypes.Route) (mtypes.Route, error)
	DeleteRoute(ctx context.Context, id string) error
	UpdateRoute(ctx context.Context, id string, r mtypes.Route) (mtypes.Route, error)

	ListWebhooks(ctx context.Context, domain string) (map[string][]string, error)
	CreateWebhook(ctx context.Context, domain, kind string, url []string) error
	DeleteWebhook(ctx context.Context, domain, kind string) error
	GetWebhook(ctx context.Context, domain, kind string) ([]string, error)
	UpdateWebhook(ctx context.Context, domain, kind string, url []string) error
	VerifyWebhookSignature(sig mtypes.Signature) (verified bool, err error)

	ListMailingLists(opts *ListOptions) *ListsIterator
	CreateMailingList(ctx context.Context, ml mtypes.MailingList) (mtypes.MailingList, error)
	DeleteMailingList(ctx context.Context, address string) error
	GetMailingList(ctx context.Context, address string) (mtypes.MailingList, error)
	UpdateMailingList(ctx context.Context, address string, ml mtypes.MailingList) (mtypes.MailingList, error)

	ListMembers(listAddress string, opts *ListOptions) *MemberListIterator
	GetMember(ctx context.Context, memberAddress, listAddress string) (mtypes.Member, error)
	CreateMember(ctx context.Context, merge bool, listAddress string, member mtypes.Member) error
	CreateMemberList(ctx context.Context, subscribed *bool, listAddress string, newMembers []any) error
	UpdateMember(ctx context.Context, memberAddress, listAddress string, member mtypes.Member) (mtypes.Member, error)
	DeleteMember(ctx context.Context, memberAddress, listAddress string) error

	ListEvents(domain string, opts *ListEventOptions) *EventIterator
	PollEvents(domain string, opts *ListEventOptions) *EventPoller

	ListIPs(ctx context.Context, dedicated, enabled bool) ([]mtypes.IPAddress, error)
	GetIP(ctx context.Context, ip string) (mtypes.IPAddress, error)
	ListDomainIPs(ctx context.Context, domain string) ([]mtypes.IPAddress, error)
	AddDomainIP(ctx context.Context, domain, ip string) error
	DeleteDomainIP(ctx context.Context, domain, ip string) error

	ListIPWarmups() *IPWarmupsIterator
	GetIPWarmup(ctx context.Context, ip string) (mtypes.IPWarmupDetails, error)
	CreateIPWarmup(ctx context.Context, ip string) error
	DeleteIPWarmup(ctx context.Context, ip string) error

	ListExports(ctx context.Context, url string) ([]mtypes.Export, error)
	GetExport(ctx context.Context, id string) (mtypes.Export, error)
	GetExportLink(ctx context.Context, id string) (string, error)
	CreateExport(ctx context.Context, url string) error

	GetTagLimits(ctx context.Context, domain string) (mtypes.TagLimits, error)

	CreateTemplate(ctx context.Context, domain string, template *mtypes.Template) error
	GetTemplate(ctx context.Context, domain, name string) (mtypes.Template, error)
	UpdateTemplate(ctx context.Context, domain string, template *mtypes.Template) error
	DeleteTemplate(ctx context.Context, domain, name string) error
	ListTemplates(domain string, opts *ListTemplateOptions) *TemplatesIterator

	AddTemplateVersion(ctx context.Context, domain, templateName string, version *mtypes.TemplateVersion) error
	GetTemplateVersion(ctx context.Context, domain, templateName, tag string) (mtypes.TemplateVersion, error)
	UpdateTemplateVersion(ctx context.Context, domain, templateName string, version *mtypes.TemplateVersion) error
	DeleteTemplateVersion(ctx context.Context, domain, templateName, tag string) error
	ListTemplateVersions(domain, templateName string, opts *ListOptions) *TemplateVersionsIterator

	ValidateEmail(ctx context.Context, email string, mailBoxVerify bool) (mtypes.ValidateEmailResponse, error)

	ListAlertsEvents(context.Context, *ListAlertsEventsOptions) (*mtypes.AlertsEventsResponse, error)
	ListAlerts(context.Context, *ListAlertsOptions) (*mtypes.AlertsSettingsResponse, error)
	AddAlert(context.Context, mtypes.AlertsEventSettingRequest) (*mtypes.AlertsEventSettingResponse, error)
	DeleteAlert(ctx context.Context, id uuid.UUID) error

	ListMonitoredDomains(opts ListMonitoredDomainsOptions) (*MonitoredDomainsIterator, error)

	ListSubaccounts(opts *ListSubaccountsOptions) *SubaccountsIterator
	CreateSubaccount(ctx context.Context, subaccountName string) (mtypes.SubaccountResponse, error)
	GetSubaccount(ctx context.Context, subaccountID string) (mtypes.SubaccountResponse, error)
	EnableSubaccount(ctx context.Context, subaccountID string) (mtypes.SubaccountResponse, error)
	DisableSubaccount(ctx context.Context, subaccountID string) (mtypes.SubaccountResponse, error)

	SetOnBehalfOfSubaccount(subaccountID string)
	RemoveOnBehalfOfSubaccount()

	ListAPIKeys(ctx context.Context, opts *ListAPIKeysOptions) ([]mtypes.APIKey, error)
	CreateAPIKey(ctx context.Context, role string, opts *CreateAPIKeyOptions) (mtypes.APIKey, error)
	DeleteAPIKey(ctx context.Context, id string) error
	RegeneratePublicAPIKey(ctx context.Context) (mtypes.RegeneratePublicAPIKeyResponse, error)
}

Mailgun defines the supported subset of the Mailgun API. The Mailgun API may contain additional features which have been deprecated since writing this SDK. This SDK only covers currently supported interface endpoints.

Note that Mailgun reserves the right to deprecate endpoints. Some endpoints listed in this interface may, at any time, become obsolete. Always double-check with the Mailgun API Documentation to determine the currently supported feature set.

type MemberListIterator

type MemberListIterator struct {
	mtypes.MemberListResponse
	// contains filtered or unexported fields
}

func (*MemberListIterator) Err

func (li *MemberListIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*MemberListIterator) First

func (li *MemberListIterator) First(ctx context.Context, items *[]mtypes.Member) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*MemberListIterator) Last

func (li *MemberListIterator) Last(ctx context.Context, items *[]mtypes.Member) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*MemberListIterator) Next

func (li *MemberListIterator) Next(ctx context.Context, items *[]mtypes.Member) bool

Next retrieves the next page of items from the api. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*MemberListIterator) Previous

func (li *MemberListIterator) Previous(ctx context.Context, items *[]mtypes.Member) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type Message

type Message interface {
	Domain() string
	To() []string
	Tags() []string
	DKIM() *bool
	SecondaryDKIM() string
	SecondaryDKIMPublic() string
	DeliveryTime() time.Time
	STOPeriod() string
	Attachments() []string
	ReaderAttachments() []ReaderAttachment
	Inlines() []string
	ReaderInlines() []ReaderAttachment
	BufferAttachments() []BufferAttachment
	NativeSend() bool
	TestMode() bool
	Tracking() *bool
	TrackingClicks() *string
	TrackingOpens() *bool
	TrackingPixelLocationTop() *string
	Headers() map[string]string
	Variables() map[string]string
	TemplateVariables() map[string]any
	RecipientVariables() map[string]map[string]any
	TemplateVersionTag() string
	TemplateRenderText() bool
	RequireTLS() bool
	SkipVerification() bool

	Specific
}

type MetricsIterator

type MetricsIterator struct {
	// contains filtered or unexported fields
}

func (*MetricsIterator) Err

func (iter *MetricsIterator) Err() error

func (*MetricsIterator) Next

func (iter *MetricsIterator) Next(ctx context.Context, resp *mtypes.MetricsResponse) (more bool)

Next retrieves the next page of items from the api. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

type MetricsOptions

type MetricsOptions = mtypes.MetricsRequest

type MimeMessage

type MimeMessage struct {
	CommonMessage
	// contains filtered or unexported fields
}

MimeMessage contains fields relevant to pre-packaged MIME messages.

func NewMIMEMessage

func NewMIMEMessage(domain string, body io.ReadCloser, to ...string) *MimeMessage

NewMIMEMessage creates a new MIME message. These messages are largely canned; you do not need to invoke setters to set message-related headers. However, you do still need to call setters for Mailgun-specific settings.

Supports arbitrary-sized recipient lists by automatically sending mail in batches of up to MaxNumberOfRecipients.

To support batch sending, do not provide `to` at this point. You can do this explicitly, or implicitly, as follows:

// Note absence of `to` parameter(s)!
m := NewMIMEMessage(domain, body)

Note that you'll need to invoke the AddRecipientAndVariables or AddRecipient method before sending, though.

func (*MimeMessage) AddBCC

func (*MimeMessage) AddBCC(_ string)

func (*MimeMessage) AddCC

func (*MimeMessage) AddCC(_ string)

func (*MimeMessage) AddRecipient

func (m *MimeMessage) AddRecipient(recipient string) error

func (*MimeMessage) AddValues

func (m *MimeMessage) AddValues(p *FormDataPayload)

func (*MimeMessage) Endpoint

func (*MimeMessage) Endpoint() string

func (*MimeMessage) IsValid

func (m *MimeMessage) IsValid() bool

func (*MimeMessage) RecipientCount

func (m *MimeMessage) RecipientCount() int

func (*MimeMessage) SetAmpHTML

func (*MimeMessage) SetAmpHTML(_ string)

func (*MimeMessage) SetHTML

func (*MimeMessage) SetHTML(_ string)

func (*MimeMessage) SetTemplate

func (*MimeMessage) SetTemplate(_ string)

type MonitoredDomainsIterator added in v5.4.0

type MonitoredDomainsIterator struct {
	// contains filtered or unexported fields
}

func (*MonitoredDomainsIterator) Err added in v5.4.0

func (iter *MonitoredDomainsIterator) Err() error

func (*MonitoredDomainsIterator) Next added in v5.4.0

func (iter *MonitoredDomainsIterator) Next(ctx context.Context, resp []mtypes.MonitoredDomain) (more bool)

Next retrieves the next page of items from the api. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

type PlainMessage

type PlainMessage struct {
	CommonMessage
	// contains filtered or unexported fields
}

PlainMessage contains fields relevant to plain API-synthesized messages. You're expected to use various setters to set most of these attributes, although from, subject, and text are set when the message is created with NewMessage.

func NewMessage

func NewMessage(domain, from, subject, text string, to ...string) *PlainMessage

NewMessage returns a new e-mail message with the simplest envelop needed to send.

Supports arbitrary-sized recipient lists by automatically sending mail in batches of up to MaxNumberOfRecipients.

To support batch sending, do not provide `to` at this point. You can do this explicitly, or implicitly, as follows:

// Note absence of `to` parameter(s)!
m := NewMessage("example.com", "[email protected]", "Help save our planet", "Hello world!")

Note that you'll need to invoke the AddRecipientAndVariables or AddRecipient method before sending, though.

func (*PlainMessage) AddBCC

func (m *PlainMessage) AddBCC(r string)

func (*PlainMessage) AddCC

func (m *PlainMessage) AddCC(r string)

func (*PlainMessage) AddRecipient

func (m *PlainMessage) AddRecipient(recipient string) error

AddRecipient appends a receiver to the To: header of a message. It will return an error if the limit of recipients has been exceeded for this message

func (*PlainMessage) AddRecipientAndVariables

func (m *PlainMessage) AddRecipientAndVariables(r string, vars map[string]any) error

AddRecipientAndVariables appends a receiver to the To: header of a message, and as well attaches a set of variables relevant for this recipient. It will return an error if the limit of recipients has been exceeded for this message

func (*PlainMessage) AddValues

func (m *PlainMessage) AddValues(p *FormDataPayload)

func (*PlainMessage) AmpHTML

func (m *PlainMessage) AmpHTML() string

func (*PlainMessage) BCC

func (m *PlainMessage) BCC() []string

func (*PlainMessage) CC

func (m *PlainMessage) CC() []string

func (*PlainMessage) Endpoint

func (*PlainMessage) Endpoint() string

func (*PlainMessage) From

func (m *PlainMessage) From() string

func (*PlainMessage) HTML

func (m *PlainMessage) HTML() string

func (*PlainMessage) IsValid

func (m *PlainMessage) IsValid() bool

func (*PlainMessage) RecipientCount

func (m *PlainMessage) RecipientCount() int

func (*PlainMessage) SetAmpHTML

func (m *PlainMessage) SetAmpHTML(h string)

func (*PlainMessage) SetHTML

func (m *PlainMessage) SetHTML(h string)

func (*PlainMessage) SetTemplate

func (m *PlainMessage) SetTemplate(t string)

func (*PlainMessage) Subject

func (m *PlainMessage) Subject() string

func (*PlainMessage) Template

func (m *PlainMessage) Template() string

func (*PlainMessage) Text

func (m *PlainMessage) Text() string

type RateLimitedError added in v5.7.0

type RateLimitedError struct {
	Err     error
	ResetAt *time.Time // If provided, the time at which the rate limit will reset.
}

func (*RateLimitedError) Error added in v5.7.0

func (e *RateLimitedError) Error() string

func (*RateLimitedError) Unwrap added in v5.7.0

func (e *RateLimitedError) Unwrap() error

type ReaderAttachment

type ReaderAttachment struct {
	Filename   string
	ReadCloser io.ReadCloser
}

type Recipient

type Recipient struct {
	Name  string `json:"-"`
	Email string `json:"-"`
}

func (Recipient) MarshalText

func (r Recipient) MarshalText() ([]byte, error)

MarshalText satisfies TextMarshaler

func (Recipient) String

func (r Recipient) String() string

func (*Recipient) UnmarshalText

func (r *Recipient) UnmarshalText(text []byte) error

UnmarshalText satisfies TextUnmarshaler

type RoutesIterator

type RoutesIterator struct {
	mtypes.RoutesListResponse
	// contains filtered or unexported fields
}

func (*RoutesIterator) Err

func (ri *RoutesIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*RoutesIterator) First

func (ri *RoutesIterator) First(ctx context.Context, items *[]mtypes.Route) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*RoutesIterator) Last

func (ri *RoutesIterator) Last(ctx context.Context, items *[]mtypes.Route) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*RoutesIterator) Next

func (ri *RoutesIterator) Next(ctx context.Context, items *[]mtypes.Route) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*RoutesIterator) Offset

func (ri *RoutesIterator) Offset() int

Offset returns the current offset of the iterator

func (*RoutesIterator) Previous

func (ri *RoutesIterator) Previous(ctx context.Context, items *[]mtypes.Route) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type Specific

type Specific interface {
	// AddCC appends a receiver to the carbon-copy header of a message.
	AddCC(string)

	// AddBCC appends a receiver to the blind-carbon-copy header of a message.
	AddBCC(string)

	// SetHTML If you're sending a message that isn't already MIME encoded, it will arrange to bundle
	// an HTML representation of your message in addition to your plain-text body.
	SetHTML(string)

	// SetAmpHTML If you're sending a message that isn't already MIME encoded, it will arrange to bundle
	// an AMP-For-Email representation of your message in addition to your HTML & plain-text content.
	SetAmpHTML(string)

	// AddValues invoked by Send() to add message-type-specific MIME headers for the API call
	// to Mailgun.
	AddValues(*FormDataPayload)

	// IsValid yields true if and only if the message is valid enough for sending
	// through the API.
	IsValid() bool

	// Endpoint tells Send() which endpoint to use to submit the API call.
	Endpoint() string

	// RecipientCount returns the total number of recipients for the message.
	// This includes To:, Cc:, and Bcc: fields.
	//
	// NOTE: At present, this method is reliable only for non-MIME messages, as the
	// Bcc: and Cc: fields are easily accessible.
	// For MIME messages, only the To: field is considered.
	// A fix for this issue is planned for a future release.
	// For now, MIME messages are always assumed to have 10 recipients between Cc: and Bcc: fields.
	// If your MIME messages have more than 10 non-To: field recipients,
	// you may find that some recipients will not receive your e-mail.
	// It's perfectly OK, of course, for a MIME message to not have any Cc: or Bcc: recipients.
	RecipientCount() int

	// SetTemplate sets the name of a template stored via the template API.
	// See https://documentation.mailgun.com/docs/mailgun/user-manual/sending-messages/#templates
	SetTemplate(string)
}

The Specific abstracts the common characteristics between plain text and MIME messages.

type SubaccountsIterator

type SubaccountsIterator struct {
	mtypes.ListSubaccountsResponse
	// contains filtered or unexported fields
}

func (*SubaccountsIterator) Err

func (ri *SubaccountsIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*SubaccountsIterator) First

func (ri *SubaccountsIterator) First(ctx context.Context, items *[]mtypes.Subaccount) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*SubaccountsIterator) Last

func (ri *SubaccountsIterator) Last(ctx context.Context, items *[]mtypes.Subaccount) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*SubaccountsIterator) Next

func (ri *SubaccountsIterator) Next(ctx context.Context, items *[]mtypes.Subaccount) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*SubaccountsIterator) Offset

func (ri *SubaccountsIterator) Offset() int

Offset returns the current offset of the iterator

func (*SubaccountsIterator) Previous

func (ri *SubaccountsIterator) Previous(ctx context.Context, items *[]mtypes.Subaccount) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type TagIterator

type TagIterator struct {
	mtypes.TagsResponse
	// contains filtered or unexported fields
}

func (*TagIterator) Err

func (ti *TagIterator) Err() error

Err returns any error if one occurred

func (*TagIterator) First

func (ti *TagIterator) First(ctx context.Context, items *[]mtypes.Tag) bool

First returns the first page in the list of tags

func (*TagIterator) Last

func (ti *TagIterator) Last(ctx context.Context, items *[]mtypes.Tag) bool

Last returns the last page in the list of tags

func (*TagIterator) Next

func (ti *TagIterator) Next(ctx context.Context, items *[]mtypes.Tag) bool

Next returns the next page in the list of tags

func (*TagIterator) Previous

func (ti *TagIterator) Previous(ctx context.Context, items *[]mtypes.Tag) bool

Previous returns the previous page in the list of tags

type TemplateVersionsIterator

type TemplateVersionsIterator struct {
	mtypes.TemplateVersionListResp
	// contains filtered or unexported fields
}

func (*TemplateVersionsIterator) Err

func (li *TemplateVersionsIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*TemplateVersionsIterator) First

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*TemplateVersionsIterator) Last

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*TemplateVersionsIterator) Next

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*TemplateVersionsIterator) Previous

func (li *TemplateVersionsIterator) Previous(ctx context.Context, items *[]mtypes.TemplateVersion) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type TemplatesIterator

type TemplatesIterator struct {
	mtypes.ListTemplateResp
	// contains filtered or unexported fields
}

func (*TemplatesIterator) Err

func (ti *TemplatesIterator) Err() error

If an error occurred during iteration `Err()` will return non nil

func (*TemplatesIterator) First

func (ti *TemplatesIterator) First(ctx context.Context, items *[]mtypes.Template) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*TemplatesIterator) Last

func (ti *TemplatesIterator) Last(ctx context.Context, items *[]mtypes.Template) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*TemplatesIterator) Next

func (ti *TemplatesIterator) Next(ctx context.Context, items *[]mtypes.Template) bool

Next retrieves the next page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*TemplatesIterator) Previous

func (ti *TemplatesIterator) Previous(ctx context.Context, items *[]mtypes.Template) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type TrackingOptions

type TrackingOptions struct {
	Tracking                 bool
	TrackingClicks           string
	TrackingOpens            bool
	TrackingPixelLocationTop string
}

TrackingOptions contains fields relevant to tracking.

type UnexpectedResponseError

type UnexpectedResponseError struct {
	Expected []int
	Actual   int
	Method   string
	URL      string
	Data     []byte
	Header   http.Header
}

UnexpectedResponseError this error will be returned whenever a Mailgun API returns an error response. Your application can check the Actual field to see the actual HTTP response code returned. URL contains the base URL accessed, sans any query parameters.

func (*UnexpectedResponseError) Error

func (e *UnexpectedResponseError) Error() string

Error() performs as String().

func (*UnexpectedResponseError) String deprecated

func (e *UnexpectedResponseError) String() string

String() converts the error into a human-readable, logfmt-compliant string. See http://godoc.org/github.com/kr/logfmt for details on logfmt formatting.

TODO(v6): this method is redundant: move into Error(). TODO(v6): this returns `ExpectedOneOf=[]int{200, 201}` but should return `ExpectedOneOf=[200 201]`.

Deprecated: use Error() instead.

type UnsubscribesIterator

type UnsubscribesIterator struct {
	mtypes.ListUnsubscribesResponse
	// contains filtered or unexported fields
}

func (*UnsubscribesIterator) Err

func (ci *UnsubscribesIterator) Err() error

Err if an error occurred during iteration `Err()` will return non nil

func (*UnsubscribesIterator) First

func (ci *UnsubscribesIterator) First(ctx context.Context, items *[]mtypes.Unsubscribe) bool

First retrieves the first page of items from the api. Returns false if there was an error. It also sets the iterator object to the first page. Use `.Err()` to retrieve the error.

func (*UnsubscribesIterator) Last

func (ci *UnsubscribesIterator) Last(ctx context.Context, items *[]mtypes.Unsubscribe) bool

Last retrieves the last page of items from the api. Calling Last() is invalid unless you first call First() or Next() Returns false if there was an error. It also sets the iterator object to the last page. Use `.Err()` to retrieve the error.

func (*UnsubscribesIterator) Next

func (ci *UnsubscribesIterator) Next(ctx context.Context, items *[]mtypes.Unsubscribe) bool

Next retrieves the next page of items from the api. Returns false when there are no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error

func (*UnsubscribesIterator) Previous

func (ci *UnsubscribesIterator) Previous(ctx context.Context, items *[]mtypes.Unsubscribe) bool

Previous retrieves the previous page of items from the api. Returns false when there no more pages to retrieve or if there was an error. Use `.Err()` to retrieve the error if any

type UpdateDomainOptions

type UpdateDomainOptions struct {
	Password                   string
	SpamAction                 mtypes.SpamAction
	Wildcard                   *bool
	WebScheme                  string
	WebPrefix                  string
	RequireTLS                 *bool
	SkipVerification           *bool
	UseAutomaticSenderSecurity *bool
	ArchiveTo                  string
	MailFromHost               string
	MessageTTL                 *int
}

UpdateDomainOptions options for updating a domain

Directories

Path Synopsis
internal
types/inboxready
Package inboxready provides primitives to interact with the openapi HTTP API.
Package inboxready provides primitives to interact with the openapi HTTP API.
Package mtypes contains API Mailgun requests, responses, and helper types.
Package mtypes contains API Mailgun requests, responses, and helper types.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL