Skip to content

mailersend/mailersend-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MailerSend Golang SDK

MIT licensed Test

Table of Contents

Installation

We recommend using this package with golang modules

$ go get github.com/mailersend/mailersend-go

Usage

Email

Send an email

package main

import (
    "context"
    "os"
    "fmt"
    "time"

    "github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	subject := "Subject"
	text := "This is the text content"
	html := "<p>This is the HTML content</p>"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}
	
	// Send in 5 minute
	sendAt := time.Now().Add(time.Minute * 5).Unix()

	tags := []string{"foo", "bar"}

	message := ms.Email.NewMessage()

	message.SetFrom(from)
	message.SetRecipients(recipients)
	message.SetSubject(subject)
	message.SetHTML(html)
	message.SetText(text)
	message.SetTags(tags)
	message.SetSendAt(sendAt)
	message.SetInReplyTo("client-id")

	res, _ := ms.Email.Send(ctx, message)

	fmt.Printf(res.Header.Get("X-Message-Id"))

}

Add CC, BCC recipients

package main

import (
	"context"
	"os"
	"fmt"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	subject := "Subject"
	text := "This is the text content"
	html := "<p>This is the HTML content</p>"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}

	cc := []mailersend.Recipient{
		{
			Name:  "CC",
			Email: "cc@client.com",
		},
	}

	bcc := []mailersend.Recipient{
		{
			Name:  "BCC",
			Email: "bcc@client.com",
		},
	}

	replyTo := mailersend.ReplyTo{
		Name:  "Reply To",
		Email: "reply_to@client.com",
	}
	
	tags := []string{"foo", "bar"}

	message := ms.Email.NewMessage()

	message.SetFrom(from)
	message.SetRecipients(recipients)
	message.SetSubject(subject)
	message.SetHTML(html)
	message.SetText(text)
	message.SetTags(tags)
	message.SetCc(cc)
	message.SetBcc(bcc)
	message.SetReplyTo(replyTo)

	res, _ := ms.Email.Send(ctx, message)

	fmt.Printf(res.Header.Get("X-Message-Id"))

}

Send a template-based email

package main

import (
    "context"
    "os"
    "fmt"
    "time"

    "github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	subject := "Subject"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}

	variables := []mailersend.Variables{
		{
			Email: "your@client.com",
			Substitutions: []mailersend.Substitution{
				{
					Var:   "foo",
					Value: "bar",
				},
			},
		},
	}

	message := ms.Email.NewMessage()

	message.SetFrom(from)
	message.SetRecipients(recipients)
	message.SetSubject(subject)
	message.SetTemplateID("template-id")
	message.SetSubstitutions(variables)
	
	res, _ := ms.Email.Send(ctx, message)

	fmt.Printf(res.Header.Get("X-Message-Id"))

}

Personalization

package main

import (
	"context"
	"os"
	"fmt"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	subject := "Subject {{ var }}"
	text := "This is the text version with a {{ var }}."
	html := "<p>This is the HTML version with a {{ var }}.</p>"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}

	personalization := []mailersend.Personalization{
		{
			Email: "your@client.com",
			Data: map[string]interface{}{
				"Var":   "value",
			},
		},
	}

	message := ms.Email.NewMessage()

	message.SetFrom(from)
	message.SetRecipients(recipients)
	message.SetSubject(subject)
	message.SetText(text)
	message.SetHTML(html)
	
	message.SetPersonalization(personalization)

	res, _ := ms.Email.Send(ctx, message)

	fmt.Printf(res.Header.Get("X-Message-Id"))

}

Send email with attachment

package main

import (
	"bufio"
	"context"
	"os"
	"encoding/base64"
	"fmt"
	"io"
	"os"
	"time"

    "github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	subject := "Subject"
	text := "This is the text content"
	html := "<p>This is the HTML content</p>"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}

	tags := []string{"foo", "bar"}

	message := ms.Email.NewMessage()

	message.SetFrom(from)
	message.SetRecipients(recipients)
	message.SetSubject(subject)
	message.SetHTML(html)
	message.SetText(text)
	message.SetTags(tags)

	// Open file on disk.
	f, _ := os.Open("./file.jpg")

	reader := bufio.NewReader(f)
	content, _ := io.ReadAll(reader)

	// Encode as base64.
	encoded := base64.StdEncoding.EncodeToString(content)

	attachment := mailersend.Attachment{Filename: "file.jpg", Content: encoded}

	message.AddAttachment(attachment)

	res, _ := ms.Email.Send(ctx, message)

	fmt.Printf(res.Header.Get("X-Message-Id"))

}

Send email with inline attachment

package main

import (
	"bufio"
	"context"
	"os"
	"encoding/base64"
	"fmt"
	"io"
	"os"
	"time"

    "github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	subject := "Subject"
	text := "This is the text content"
	html := "<p>This is the HTML content</p> <p><img src=\"cid:image.jpeg\"/></p>"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}

	tags := []string{"foo", "bar"}

	message := ms.Email.NewMessage()

	message.SetFrom(from)
	message.SetRecipients(recipients)
	message.SetSubject(subject)
	message.SetHTML(html)
	message.SetText(text)
	message.SetTags(tags)

	// Open file on disk.
	f, _ := os.Open("./image.jpeg")

	reader := bufio.NewReader(f)
	content, _ := io.ReadAll(reader)

	// Encode as base64.
	encoded := base64.StdEncoding.EncodeToString(content)

	// Inside template add <img src="cid:image.jpg"/> should match ID 
	attachment := mailersend.Attachment{Filename: "image.jpeg", ID: "image.jpeg", Content: encoded, Disposition: mailersend.DispositionInline}

	message.AddAttachment(attachment)

	res, _ := ms.Email.Send(ctx, message)

	fmt.Printf(res.Header.Get("X-Message-Id"))

}

Bulk Email

Send bulk email

package main

import (
    "context"
    "os"
	"time"
	"log"
	"fmt"
	
    "github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
	
	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()

	subject := "Subject"
	text := "This is the text content"
	html := "<p>This is the HTML content</p>"

	from := mailersend.From{
		Name:  "Your Name",
		Email: "your@domain.com",
	}

	recipients := []mailersend.Recipient{
		{
			Name:  "Your Client",
			Email: "your@client.com",
		},
	}

	var messages []*mailersend.Message
	
	for i := range [2]int{} {
		msg := &mailersend.Message{
			From:       from,
			Recipients: recipients,
			Subject:    fmt.Sprintf("%s %v", subject, i),
			Text:       text,
			HTML:       html,
		}
		messages = append(messages, msg)
	}
	
	_, _, err := ms.BulkEmail.Send(ctx, messages)
	if err != nil {
		log.Fatal(err)
	}

}

Get bulk email status

package main

import (
	"context"
	"os"
	"time"
	"log"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	_, _, err := ms.BulkEmail.Status(ctx, "bulk-email-id")
	if err != nil {
		log.Fatal(err)
	}
	
}

Activity

Get a list of activities

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	from := time.Now().Add(-24 * time.Hour).Unix()
	to := time.Now().Unix()
	domainID := "domain-id"

	options := &mailersend.ActivityOptions{
		DomainID: domainID,
		DateFrom: from, 
		DateTo: to,
	}
	
	_, _, err := ms.Activity.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Analytics

Activity data by date

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	from := time.Now().Add(-24 * time.Hour).Unix()
	to := time.Now().Unix()
	domainID := "domain-id"
	events := []string{"sent", "queued"}

	options := &mailersend.AnalyticsOptions{
		DomainID:    domainID,
		DateFrom:    from,
		DateTo:      to,
		Event:       events,
	}

	_, _, err := ms.Analytics.GetActivityByDate(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Opens by country

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	from := time.Now().Add(-24 * time.Hour).Unix()
	to := time.Now().Unix()
	domainID := "domain-id"

	options := &mailersend.AnalyticsOptions{
		DomainID: domainID,
		DateFrom: from,
		DateTo:   to,
	}

	_, _, err := ms.Analytics.GetOpensByCountry(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Opens by user-agent name

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	from := time.Now().Add(-24 * time.Hour).Unix()
	to := time.Now().Unix()
	domainID := "domain-id"

	options := &mailersend.AnalyticsOptions{
		DomainID: domainID,
		DateFrom: from,
		DateTo:   to,
	}

	_, _, err := ms.Analytics.GetOpensByUserAgent(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Opens by reading environment

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	from := time.Now().Add(-24 * time.Hour).Unix()
	to := time.Now().Unix()
	domainID := "domain-id"

	options := &mailersend.AnalyticsOptions{
		DomainID: domainID,
		DateFrom: from,
		DateTo:   to,
	}

	_, _, err := ms.Analytics.GetOpensByReadingEnvironment(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Inbound Routes

Get a list of inbound routes

package main

import (
	"context"
	"os"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	domainID := "domain-id"

	listOptions := &mailersend.ListInboundOptions{
		DomainID: domainID,
	}
	
	_, _, _ = ms.Inbound.List(ctx, listOptions)
}

Get a single inbound route

package main

import (
	"context"
	"os"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	inboundID := "inbound-id"

	_, _, _ = ms.Inbound.Get(ctx, inboundID)
}

Add an inbound route

package main

import (
	"context"
	"os"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	domainID := "domain-id"

	createOptions := &mailersend.CreateInboundOptions{
		DomainID:      domainID,
		Name:          "Example Route",
		DomainEnabled: *mailersend.Bool(false),
		MatchFilter: &mailersend.MatchFilter{
			Type: "match_all",
		},
		InboundPriority: 1,
		CatchFilter: &mailersend.CatchFilter{},
		Forwards: []mailersend.Forwards{
			{
				Type:  "webhook",
				Value: "https://example.com",
			},
		},
	}

	_, _, _ = ms.Inbound.Create(ctx, createOptions)
}

Update an inbound route

package main

import (
	"context"
	"os"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	inboundID := "inbound-id"

	updateOptions := &mailersend.UpdateInboundOptions{
		Name:          "Example Route",
		DomainEnabled: *mailersend.Bool(true),
		InboundDomain: "inbound.example.com",
		InboundPriority: 1,
		MatchFilter: &mailersend.MatchFilter{
			Type: "match_all",
		},
		CatchFilter: &mailersend.CatchFilter{
			Type: "catch_recipient",
			Filters: []mailersend.Filter{
				{
					Comparer: "equal",
					Value:    "email",
				},
				{
					Comparer: "equal",
					Value:    "emails",
				},
			},
		},
		Forwards: []mailersend.Forwards{
			{
				Type:  "webhook",
				Value: "https://example.com",
			},
		},
	}

	_, _, _ = ms.Inbound.Update(ctx, inboundID, updateOptions)
}

Delete an inbound route

package main

import (
	"context"
	"os"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	inboundID := "inbound-id"

	_, _ = ms.Inbound.Delete(ctx, inboundID)
}

Domains

Get a list of domains

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListDomainOptions{
		Page:  1,
		Limit: 25,
	}

	_, _, err := ms.Domain.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single domain

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	domainID := "domain-id"

	_, _, err := ms.Domain.Get(ctx, domainID)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a domain

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	domainID := "domain-id"

	_, err := ms.Domain.Delete(ctx, domainID)
	if err != nil {
		log.Fatal(err)
	}
}

Add a domain

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.CreateDomainOptions{
		Name: "domain.test",
	}

	_, _, err := ms.Domain.Create(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get DNS Records

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"

	_, _, err := ms.Domain.GetDNS(ctx, domainID)
	if err != nil {
		log.Fatal(err)
	}
}

Get verification status

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"

	_, _, err := ms.Domain.Verify(ctx, domainID)
	if err != nil {
		log.Fatal(err)
	}
}

Get a list of recipients per domain

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"
	
	options := &mailersend.GetRecipientsOptions{
	 	DomainID: domainID,
	 	Page:     1,
	 	Limit:    25,
	}
	
	_, _, err := ms.Domain.GetRecipients(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Update domain settings

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"
	
	options := &mailersend.DomainSettingOptions{
		DomainID:    domainID,
		SendPaused:  mailersend.Bool(false),
		TrackClicks: mailersend.Bool(true),
	}
	
	_, _, err := ms.Domain.Update(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Messages

Get a list of messages

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListMessageOptions{
		Page:  1,
		Limit: 25,
	}

	_, _, err := ms.Message.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single message

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	messageID := "message-id"

	_, _, err := ms.Message.Get(ctx, messageID)
	if err != nil {
		log.Fatal(err)
	}
}

Scheduled messages

Get a list of scheduled messages

package main

import (
	"context"
	"os"
	"log"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	domainID := "domain-id"

	_, _, err := ms.ScheduleMessage.List(ctx, domainID)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single scheduled message

package main

import (
	"context"
	"os"
	"log"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()
	
	messageID := "message-id"

	_, _, err := ms.ScheduleMessage.Get(ctx, messageID)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a scheduled message

package main

import (
	"context"
	"os"
	"log"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.TODO()

	messageID := "message-id"
	
	_, err := ms.ScheduleMessage.Delete(ctx, messageID)
	if err != nil {
		log.Fatal(err)
	}
}

Recipients

Get a list of recipients

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListRecipientOptions{
		//DomainID: domainID,
		Page:  1,
		Limit: 25,
	}
	
	_, _, err := ms.Recipient.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single recipient

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	recipientID := "recipient-id"

	_, _, err := ms.Recipient.Get(ctx, recipientID)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a recipient

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	recipientID := "recipient-id"
	
	_, err := ms.Recipient.Delete(ctx, recipientID)
	if err != nil {
		log.Fatal(err)
	}
}

Get recipients from a suppression list

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	listOptions := &mailersend.SuppressionOptions{
		DomainID: "domain-id",
		Page:     1,
		Limit:    25,
	}

	// List Block List Recipients 
	_, _, err := ms.Suppression.ListBlockList(ctx, listOptions)
	if err != nil {
		log.Fatal(err)
	}

	// List Hard Bounces 
	_, _, _ = ms.Suppression.ListHardBounces(ctx, listOptions)

	// List Spam Complaints 
	_, _, _ = ms.Suppression.ListSpamComplaints(ctx, listOptions)
	
	// List Unsubscribes
	_, _, _ = ms.Suppression.ListUnsubscribes(ctx, listOptions)


}

Add recipients to a suppression list

package main

import (
	"context"
	"os"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	// Add Recipient to Block List
	createSuppressionBlockOptions := &mailersend.CreateSuppressionBlockOptions{
		DomainID:   "domain-id",
		Recipients: []string{"test@example.com"},
		Patterns: []string{".*@example.com"},
	}
	
	_, _, _ = ms.Suppression.CreateBlock(ctx, createSuppressionBlockOptions)

	// Add Recipient to Hard Bounces
	createSuppressionHardBounceOptions := &mailersend.CreateSuppressionOptions{
		DomainID:   "domain-id",
		Recipients: []string{"test@example.com"},
	}

	_, _, _ = ms.Suppression.CreateHardBounce(ctx, createSuppressionHardBounceOptions)

	// Add Recipient to Spam Complaints
	createSuppressionSpamComplaintsOptions := &mailersend.CreateSuppressionOptions{
		DomainID:   "domain-id",
		Recipients: []string{"test@example.com"},
	}

	_, _, _ = ms.Suppression.CreateHardBounce(ctx, createSuppressionSpamComplaintsOptions)

	// Add Recipient to Unsubscribes
	createSuppressionUnsubscribesOptions := &mailersend.CreateSuppressionOptions{
		DomainID:   "domain-id",
		Recipients: []string{"test@example.com"},
	}
	
	_, _, _ = ms.Suppression.CreateHardBounce(ctx, createSuppressionUnsubscribesOptions)

}

Delete recipients from a suppression list

package main

import (
	"context"
	"os"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"

	// Delete All {type}
	
	// mailersend.BlockList 
	// mailersend.HardBounces 
	// mailersend.SpamComplaints 
	// mailersend.Unsubscribes
	
	_, _ = ms.Suppression.DeleteAll(ctx, domainID, mailersend.Unsubscribes)
	
	// Delete 

	deleteSuppressionOption := &mailersend.DeleteSuppressionOptions{
		DomainID: domainID,
		Ids:      []string{"suppression-id"},
	}

	_, _ = ms.Suppression.Delete(ctx, deleteSuppressionOption, mailersend.Unsubscribes)


}

Tokens

Create a token

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"
	
	scopes := []string{
		"tokens_full", 
		"email_full",
		"domains_full",
		"activity_full",
		"analytics_full",
		"webhooks_full",
		"templates_full",
	}

	options := &mailersend.CreateTokenOptions{
		Name:     "token name",
		DomainID: domainID,
		Scopes:   scopes,
	}

	newToken, _, err := ms.Token.Create(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
	
	// Make sure you keep your access token secret
	log.Print(newToken.Data.AccessToken)
}

Pause / Unpause Token

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	tokenID := "token-id"
	
	updateOptions := &mailersend.UpdateTokenOptions{
		TokenID: tokenID,
		Status:  "pause/unpause",
	}

	_, _, err := ms.Token.Update(ctx, updateOptions)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a Token

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	tokenID := "token-id"
	
	_, err := ms.Token.Delete(ctx, tokenID)
	if err != nil {
		log.Fatal(err)
	}
}

Webhooks

Get a list of webhooks

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"
	
	options := &mailersend.ListWebhookOptions{
		DomainID: domainID,
		Limit:    25,
	}

	_, _, err := ms.Webhook.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single webhook

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	webhookID := "webhook-id"
	
	_, _, err := ms.Webhook.Get(ctx, webhookID)
	if err != nil {
		log.Fatal(err)
	}
}

Create a Webhook

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	domainID := "domain-id"
	events := []string{"activity.opened", "activity.clicked"}

	createOptions := &mailersend.CreateWebhookOptions{
		Name:     "Webhook",
		DomainID: domainID,
		URL:      "https://test.com",
		Enabled:  mailersend.Bool(false),
		Events:   events,
	}
	
	_, _, err := ms.Webhook.Create(ctx, createOptions)
	if err != nil {
		log.Fatal(err)
	}
}

Update a Webhook

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	webhookID := "webhook-id"
	events := []string{"activity.clicked"}

	updateOptions := &mailersend.UpdateWebhookOptions{
		WebhookID: webhookID,
		Enabled:   mailersend.Bool(true),
		Events:    events,
	}
	
	_, _, err := ms.Webhook.Update(ctx, updateOptions)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a Webhook

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	webhookID := "webhook-id"
	
	_, err := ms.Webhook.Delete(ctx, webhookID)
	if err != nil {
		log.Fatal(err)
	}
}

Templates

Get a list of templates

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	options := &mailersend.ListTemplateOptions{
		Page:  1,
		Limit: 25,
	}
	
	_, _, err := ms.Template.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single template

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	templateID := "template-id"
	
	_, _, err := ms.Template.Get(ctx, templateID)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a template

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	templateID := "template-id"
	
	_, err := ms.Template.Delete(ctx, templateID)
	if err != nil {
		log.Fatal(err)
	}
}

Email Verification

Verify a single email

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.SingleEmailVerificationOptions{
		Email: "john@doe.com"
	}

	_, _, err := ms.EmailVerification.VerifySingle(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get all email verification lists

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListEmailVerificationOptions{
		Page:  1,
		Limit: 25,
	}

	_, _, err := ms.EmailVerification.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get an email verification list

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.EmailVerification.Get(ctx, "email-verification-id")
	if err != nil {
		log.Fatal(err)
	}
}

Create an email verification list

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.CreateEmailVerificationOptions{
		Name:   "Email Verification List ",
		Emails: []string{"your@client.com", "your@client.eu"},
	}
	
	_, _, err := ms.EmailVerification.Create(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Verify an email list

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	_, _, err := ms.EmailVerification.Verify(ctx, "email-verification-id")
	if err != nil {
		log.Fatal(err)
	}
}

Get email verification list results

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.GetEmailVerificationOptions{
		EmailVerificationId: "email-verification-id",
		Page:                1,
		Limit:               25,
	}

	_, _, err := ms.EmailVerification.GetResults(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

SMS

Send an SMS

package main

import (
	"context"
	"os"
	"fmt"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	message := ms.Sms.NewMessage()
	message.SetFrom("your-number")
	message.SetTo([]string{"client-number"})
	message.SetText("This is the message content {{ var }}")

	personalization := []mailersend.SmsPersonalization{
		{
			PhoneNumber: "client-number",
			Data: map[string]interface{}{
				"var": "foo",
			},
		},
	}

	message.SetPersonalization(personalization)

	res, _ := ms.Sms.Send(context.TODO(), message)
	fmt.Printf(res.Header.Get("X-SMS-Message-Id"))
}

SMS Messages

Get a list of SMS messages

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListSmsMessageOptions{
		Limit: 10,
	}

	_, _, err := ms.SmsMessage.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get info on an SMS message

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.SmsMessage.Get(ctx, "sms-message-id")
	if err != nil {
		log.Fatal(err)
	}
}

SMS Activity

Get a list of SMS activities

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.SmsActivityOptions{}
	
	_, _, err := ms.SmsActivityService.List(context.TODO(), options)
	if err != nil {
		log.Fatal(err)
	}
}

Get activity of a single SMS message

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.SmsActivityService.Get(context.TODO(), "message-id")
	if err != nil {
		log.Fatal(err)
	}
}

SMS phone numbers

Get a list of SMS phone numbers

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.SmsNumberOptions{}

	_, _, err := ms.SmsNumber.List(context.TODO(), options)
	if err != nil {
		log.Fatal(err)
	}
}

Get an SMS phone number

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.SmsNumber.Get(context.TODO(), "number-id")
	if err != nil {
		log.Fatal(err)
	}
}

Update a single SMS phone number

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.SmsNumberSettingOptions{
		Id:     "number-id",
		Paused: mailersend.Bool(false),
	}

	_, _, err := ms.SmsNumber.Update(context.TODO(), options)
	if err != nil {
		log.Fatal(err)
	}
}

Delete an SMS phone number

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	numberID := "number-id"

	_, err := ms.SmsNumber.Delete(ctx, numberID)
	if err != nil {
		log.Fatal(err)
	}
}

SMS recipients

Get a list of SMS recipients

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.SmsRecipientOptions{SmsNumberId: "sms-number-id"}
	
	_, _, err := ms.SmsRecipient.List(context.TODO(), options)
	if err != nil {
		log.Fatal(err)
	}
}

Get an SMS recipient

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.SmsRecipient.Get(context.TODO(), "sms-recipient-id")
	if err != nil {
		log.Fatal(err)
	}
}

Update a single SMS recipient

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.SmsRecipientSettingOptions{
		Id:     "sms-recipient-id",
		Status: "opt_out",
	}

	_, _, err := ms.SmsRecipient.Update(context.TODO(), options)
	if err != nil {
		log.Fatal(err)
	}
}

SMS inbounds

Get a list of SMS inbound routes

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	listOptions := &mailersend.ListSmsInboundOptions{
		SmsNumberId: "sms-number-id",
	}
	
	_, _, err := ms.SmsInbound.List(ctx, listOptions)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single SMS inbound route

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.SmsInbound.Get(ctx, "sms-inbound-id")
	if err != nil {
		log.Fatal(err)
	}
	
}

Create an SMS inbound route

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.CreateSmsInboundOptions{
		SmsNumberId: "sms-number-id",
		Name:        "Example Route",
		ForwardUrl:  "https://example.com",
		Filter: mailersend.Filter{
			Comparer: "equal",
			Value:    "START",
		},
		Enabled: mailersend.Bool(true),
	}
	
	_, _, err := ms.SmsInbound.Create(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Update an SMS inbound route

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	options := &mailersend.UpdateSmsInboundOptions{
		Id:          "sms-inbound-id",
		SmsNumberId: "sms-number-id",
		Name:        "Example Route",
		ForwardUrl:  "https://example.com",
		Filter: mailersend.Filter{
			Comparer: "equal",
			Value:    "START",
		},
		Enabled: mailersend.Bool(false),
	}

	_, _, err := ms.SmsInbound.Update(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Delete an SMS inbound route

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, err := ms.SmsInbound.Delete(ctx, "sms-inbound-id")
	if err != nil {
		log.Fatal(err)
	}
}

SMS webhooks

Get a list of SMS webhooks

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListSmsWebhookOptions{
		SmsNumberId: "sms-number-id",
	}

	_, _, err := ms.SmsWebhook.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get an SMS webhook

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.SmsWebhook.Get(ctx, "sms-webhook-id")
	if err != nil {
		log.Fatal(err)
	}
	
}

Create an SMS webhook

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	events := []string{"sms.sent"}
	
	options := &mailersend.CreateSmsWebhookOptions{
		SmsNumberId: "sms-number-id",
		Name:        "Webhook",
		Events:      events,
		URL:         "https://test.com",
		Enabled:  mailersend.Bool(false),
	}
	
	_, _, err := ms.SmsWebhook.Create(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Update an SMS webhook

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	events := []string{"sms.sent"}

	options := &mailersend.UpdateSmsWebhookOptions{
		Id:   "sms-webhook-id",
		Name: "Webhook",
		Events: events,
		Enabled: mailersend.Bool(true),
		URL:    "https://test.com",
	}
	
	_, _, err := ms.SmsWebhook.Update(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Delete an SMS webhook

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	_, err := ms.SmsWebhook.Delete(ctx, "sms-webhook-id")
	if err != nil {
		log.Fatal(err)
	}
}

Sender identities

Get a list of Sender Identities

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.ListIdentityOptions{
		DomainID: "domain-id",
	}

	_, _, err := ms.Identity.List(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Get a single Sender Identity

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.Identity.Get(ctx, "identity-id")
	if err != nil {
		log.Fatal(err)
	}
}

Get a single Sender Identity By Email

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.Identity.GetByEmail(ctx, "identity-email")
	if err != nil {
		log.Fatal(err)
	}
}

Create a Sender Identity

package main

import (
	"context"
	"os"
	"log"
	"time"
	
	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

	ctx := context.Background()
	ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
	defer cancel()
	
	options := &mailersend.CreateIdentityOptions{
		DomainID: "domain-id",
		Name:     "Sender Name",
		Email:    "Sender Email",
	}
	
	_, _, err := ms.Identity.Create(ctx, options)
	if err != nil {
		log.Fatal(err)
	}
}

Update a Sender Identity

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.UpdateIdentityOptions{
		Name:            "Sender Name",
		ReplyToEmail:    "Reply To Email",
	}

	_, _, err := ms.Identity.Update(ctx, "identity-id", options)
	if err != nil {
		log.Fatal(err)
	}
}

Update a Sender Identity By Email

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	options := &mailersend.UpdateIdentityOptions{
		Name:            "Sender Name",
		ReplyToEmail:    "Reply To Email",
	}

	_, _, err := ms.Identity.UpdateByEmail(ctx, "identity-email", options)
	if err != nil {
		log.Fatal(err)
	}
}

Delete a Sender Identity

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, err := ms.Identity.Delete(ctx, "identity-id")
	if err != nil {
		log.Fatal(err)
	}
}

Delete a Sender Identity By Email

package main

import (
	"context"
	"os"
	"log"
	"time"

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, err := ms.Identity.DeleteByEmail(ctx, "identity-email")
	if err != nil {
		log.Fatal(err)
	}
}

Other Endpoints

Get an API Quota

package main

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

	"github.com/mailersend/mailersend-go"
)

func main() {
	// Create an instance of the mailersend client
	ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))

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

	_, _, err := ms.ApiQuota.Get(ctx)
	if err != nil {
		log.Fatal(err)
	}
}

Types

Most API responses are Unmarshalled into their corresponding types.

You can see all available types on pkg.go.dev

https://pkg.go.dev/github.com/mailersend/mailersend-go#pkg-types

Helpers

We provide a few helpers to help with development.

// Create a pointer to a true boolean 
mailersend.Bool(true)

// Create a pointer to a false boolean
mailersend.Bool(false)

// Create a pointer to a Int
mailersend.Int(2)

// Create a pointer to a Int64
mailersend.Int64(2)

// Create a pointer to a String
mailersend.String("string")

Testing

pkg/testing

$ go test

Available endpoints

Feature group Endpoint Available
Email POST send

If, at the moment, some endpoint is not available, please use other available tools to access it. Refer to official API docs for more info.

Support and Feedback

In case you find any bugs, submit an issue directly here in GitHub.

You are welcome to create SDK for any other programming language.

If you have any troubles using our API or SDK free to contact our support by email info@mailersend.com

The official documentation is at https://developers.mailersend.com

License

The MIT License (MIT)