MailerSend Golang SDK
- Installation
- Usage
- 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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
// 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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
cc := []mailersend.Recipient{
{
Name: "CC",
Email: "[email protected]",
},
}
bcc := []mailersend.Recipient{
{
Name: "BCC",
Email: "[email protected]",
},
}
replyTo := mailersend.ReplyTo{
Name: "Reply To",
Email: "[email protected]",
}
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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
variables := []mailersend.Variables{
{
Email: "[email protected]",
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"))
}
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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
personalization := []mailersend.Personalization{
{
Email: "[email protected]",
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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
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: "[email protected]",
}
recipients := []mailersend.Recipient{
{
Name: "Your Client",
Email: "[email protected]",
},
}
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"
"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)
}
}
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{"[email protected]"},
Patterns: []string{".*@example.com"},
}
_, _, _ = ms.Suppression.CreateBlock(ctx, createSuppressionBlockOptions)
// Add Recipient to Hard Bounces
createSuppressionHardBounceOptions := &mailersend.CreateSuppressionOptions{
DomainID: "domain-id",
Recipients: []string{"[email protected]"},
}
_, _, _ = ms.Suppression.CreateHardBounce(ctx, createSuppressionHardBounceOptions)
// Add Recipient to Spam Complaints
createSuppressionSpamComplaintsOptions := &mailersend.CreateSuppressionOptions{
DomainID: "domain-id",
Recipients: []string{"[email protected]"},
}
_, _, _ = ms.Suppression.CreateHardBounce(ctx, createSuppressionSpamComplaintsOptions)
// Add Recipient to Unsubscribes
createSuppressionUnsubscribesOptions := &mailersend.CreateSuppressionOptions{
DomainID: "domain-id",
Recipients: []string{"[email protected]"},
}
_, _, _ = 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,
}
_, _, 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,
}
_, _, 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: "[email protected]"
}
_, _, 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{"[email protected]", "[email protected]"},
}
_, _, 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"
"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"
"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")
$ 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 [email protected]
The official documentation is at https://developers.mailersend.com