MailerSend Golang SDK
- Installation
- Usage
- Bulk Email
- Activity
- Analytics
- Inbound Routes
- Domains
- Messages
- Scheduled Messages
- Recipients
- Tokens
- Webhooks
- Templates
- Email Verification
- SMS
- SMS Messages
- SMS Activity
- SMS Phone Numbers
- SMS Recipients
- SMS Inbounds
- SMS Webhooks
- Sender Identities
- SMTP Users
- Users
- DMARC Monitoring
- Other Endpoints
- Types
- Helpers
- Testing
- Support and Feedback
- License
We recommend using this package with golang modules
$ go get github.com/mailersend/mailersend-go
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"))
}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"))
}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)
// Optional: language code for the template (e.g. "de", "fr", "pt-BR").
// Supported: de, en, es, fr, it, lt, nl, pl, pt-BR. Only used with a template.
message.SetLanguage("pt-BR")
res, _ := ms.Email.Send(ctx, message)
fmt.Printf(res.Header.Get("X-Message-Id"))
}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"))
}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"))
}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"))
}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)
}
}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)
}
}package main
import (
"context"
"fmt"
"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,
Event: []string{"suppressed"},
}
res, _, err := ms.Activity.List(ctx, options)
if err != nil {
log.Fatal(err)
}
// For activities with Type "suppressed", SuppressionReason explains why the
// recipient was suppressed (on_hold, hard_bounced, unsubscribed,
// spam_complained or blocklisted). It is empty for all other types.
for _, activity := range res.Data {
fmt.Printf("%s %s\n", activity.Type, activity.SuppressionReason)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}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)
}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)
}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)
}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)
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}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)
}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)
}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)
}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)
}
}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)
}
}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)
}
}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)
}
}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,
Version: mailersend.Int(2),
}
_, _, err := ms.Webhook.Create(ctx, createOptions)
if err != nil {
log.Fatal(err)
}
}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,
Version: mailersend.Int(2),
}
_, _, err := ms.Webhook.Update(ctx, updateOptions)
if err != nil {
log.Fatal(err)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
message := ms.WhatsApp.NewMessage()
message.SetFrom("12345678901")
message.SetTo([]string{"19191234567"})
message.SetTemplateID("your-template-id")
res, err := ms.WhatsApp.Send(ctx, message)
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Header.Get("X-Message-Id"))
}Values are positional: the first value in each array replaces {{1}} in that section of the template, the second replaces {{2}}, and so on. The number of values must match the number of variables the template has in that section, for every recipient.
Only variables in URL buttons are personalized, so Buttons holds the URL parameters that get appended to each button's base URL, in the order the buttons appear in the template.
package main
import (
"context"
"fmt"
"log"
"os"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
message := ms.WhatsApp.NewMessage()
message.SetFrom("12345678901")
message.SetTo([]string{"19191234567", "19199876543"})
message.SetTemplateID("your-template-id")
personalization := []mailersend.WhatsAppPersonalization{
{
To: "19191234567",
Data: mailersend.WhatsAppPersonalizationData{
Header: []string{"John"},
Body: []string{"order #1234", "tomorrow"},
Buttons: []string{"orders/1234"},
},
},
{
To: "19199876543",
Data: mailersend.WhatsAppPersonalizationData{
Header: []string{"Jane"},
Body: []string{"order #5678", "Friday"},
Buttons: []string{"orders/5678"},
},
},
}
message.SetPersonalization(personalization)
res, err := ms.WhatsApp.Send(ctx, message)
if err != nil {
log.Fatal(err)
}
fmt.Println(res.Header.Get("X-Message-Id"))
}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"))
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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)
}
}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.ListSmtpUserOptions{
Page: 1,
Limit: 25,
}
_, _, err := ms.SmtpUser.List(ctx, domainID, options)
if err != nil {
log.Fatal(err)
}
}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"
smtpUserID := "smtp-user-id"
_, _, err := ms.SmtpUser.Get(ctx, domainID, smtpUserID)
if err != nil {
log.Fatal(err)
}
}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.CreateSmtpUserOptions{
Name: "SMTP User Name",
Enabled: mailersend.Bool(true),
}
_, _, err := ms.SmtpUser.Create(ctx, domainID, options)
if err != nil {
log.Fatal(err)
}
}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"
smtpUserID := "smtp-user-id"
options := &mailersend.UpdateSmtpUserOptions{
Name: "Updated SMTP User Name",
Enabled: mailersend.Bool(false),
}
_, _, err := ms.SmtpUser.Update(ctx, domainID, smtpUserID, options)
if err != nil {
log.Fatal(err)
}
}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"
smtpUserID := "smtp-user-id"
_, err := ms.SmtpUser.Delete(ctx, domainID, smtpUserID)
if err != nil {
log.Fatal(err)
}
}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.ListUserOptions{
Page: 1,
Limit: 25,
}
_, _, err := ms.User.List(ctx, options)
if err != nil {
log.Fatal(err)
}
}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.User.Get(ctx, "user-id")
if err != nil {
log.Fatal(err)
}
}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.InviteUserOptions{
Email: "newuser@example.com",
Role: "member", // Options: "admin", "member"
}
_, _, err := ms.User.Invite(ctx, options)
if err != nil {
log.Fatal(err)
}
}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.UpdateUserOptions{
Role: "admin",
}
_, _, err := ms.User.Update(ctx, "user-id", options)
if err != nil {
log.Fatal(err)
}
}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.User.Delete(ctx, "user-id")
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.ListDmarcMonitorOptions{
Page: 1,
Limit: 25,
}
_, _, err := ms.DmarcMonitoring.List(ctx, options)
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.CreateDmarcMonitorOptions{
DomainID: "domain-id",
}
_, _, err := ms.DmarcMonitoring.Create(ctx, options)
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.UpdateDmarcMonitorOptions{
MonitorID: "monitor-id",
WantedDmarcRecord: "v=DMARC1; p=reject;",
}
_, _, err := ms.DmarcMonitoring.Update(ctx, options)
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err := ms.DmarcMonitoring.Delete(ctx, "monitor-id")
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.ListDmarcReportOptions{
MonitorID: "monitor-id",
Page: 1,
Limit: 25,
}
_, _, err := ms.DmarcMonitoring.GetAggregatedReport(ctx, options)
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, _, err := ms.DmarcMonitoring.GetIPReport(ctx, "monitor-id", "1.2.3.4")
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
options := &mailersend.ListDmarcReportSourcesOptions{
MonitorID: "monitor-id",
Page: 1,
Limit: 25,
}
_, _, err := ms.DmarcMonitoring.GetReportSources(ctx, options)
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err := ms.DmarcMonitoring.MarkIPFavorite(ctx, "monitor-id", "1.2.3.4")
if err != nil {
log.Fatal(err)
}
}package main
import (
"context"
"os"
"log"
"time"
"github.com/mailersend/mailersend-go"
)
func main() {
ms := mailersend.NewMailersend(os.Getenv("MAILERSEND_API_KEY"))
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
defer cancel()
_, err := ms.DmarcMonitoring.RemoveIPFavorite(ctx, "monitor-id", "1.2.3.4")
if err != nil {
log.Fatal(err)
}
}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)
}
}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
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")We provide interfaces for all services to help with testing
type mockDomainService struct {
mailersend.DomainService
}
func (m *mockDomainService) List(ctx context.Context, options *ListDomainOptions) (*DomainRoot, *Response, error) {
return &mailersend.DomainRoot{Data: []mailersend.Domain{{Name: "example.com"}}}, nil, nil
}
func TestListDomains(t *testing.T) {
client := &mailersend.Client{}
client.Domain = &mockDomainService{}
ctx := context.Background()
result, _, err := client.Domain.List(ctx, nil)
if err != nil || len(result.Data) == 0 || result.Data[0].Name != "example.com" {
t.Fatalf("mock failed")
}
}$ go test
| Feature group | Endpoint | Available |
|---|---|---|
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.
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