Golang email library

Generate test email accounts and real inboxes in Golang using MailSlurp SDKs. Free for personal use, send and receive emails and attachments in Go code and tests.

Code samples

import (
    mailslurp "github.com/mailslurp/mailslurp-client-go"

// create a client and a context 
func createClient(t *testing.T) (*mailslurp.APIClient, context.Context) {
    // read mailslurp api key from environment variable
    var apiKey = os.Getenv("API_KEY")
    assert.NotEmpty(t, apiKey, "API KEY is empty")

    // create a context with your api key
    ctx := context.WithValue(
        mailslurp.APIKey{Key: apiKey},

    // create mailslurp client
    config := mailslurp.NewConfiguration()
    return mailslurp.NewAPIClient(config), ctx

func Test_CanCreateInbox(t *testing.T) {
    client, ctx := createClient(t)

    // call inbox controller to create an inbox
    opts := &mailslurp.CreateInboxOpts{}
    inbox, response, err := client.InboxControllerApi.CreateInbox(ctx, opts)

    assert.Nil(t, err)
    assert.Equal(t, response.StatusCode, 201)
    assert.NotNil(t, inbox.Id)
    assert.Contains(t, inbox.EmailAddress, "@mailslurp.com")

Get started