Misar Docs
MisarMailMisar.BlogMisarReachMisarPostMisar.DevMisar PlatformMisar IdentityMisar Posts API
Sdks

Go SDK

Install and use the MisarMail Go SDK

Installation

go get github.com/misarai/misarmail-go

Quick Start

package main

import (
	"context"
	"fmt"
	"log"
	"os"

	misarmail "github.com/misarai/misarmail-go"
)

func main() {
	client := misarmail.NewClient(os.Getenv("MISARMAIL_API_KEY"))

	result, err := client.Send(context.Background(), misarmail.SendRequest{
		From:    misarmail.Address{Email: "[email protected]", Name: "Misar"},
		To:      []misarmail.Address{{Email: "[email protected]"}},
		Subject: "Welcome",
		HTML:    "<p>Hello from MisarMail!</p>",
	})
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println("Sent:", result.MessageID)
}

Available Methods

MethodDescription
client.Send(ctx, req)Send a transactional email
client.Contacts.List(ctx, params)List contacts with optional filters
client.Contacts.Create(ctx, req)Create a contact
client.Contacts.Get(ctx, id)Get a single contact
client.Contacts.Update(ctx, id, req)Update contact fields
client.Contacts.Delete(ctx, id)Delete a contact
client.Contacts.Import(ctx, req)Bulk import/upsert contacts
client.Campaigns.List(ctx, params)List campaigns
client.Campaigns.Create(ctx, req)Create a draft campaign
client.Campaigns.Get(ctx, id)Get a campaign
client.Campaigns.Update(ctx, id, req)Update a campaign
client.Campaigns.Send(ctx, id)Send/schedule a campaign
client.Campaigns.Delete(ctx, id)Delete a campaign
client.Templates.List(ctx, params)List email templates
client.Templates.Create(ctx, req)Create a template
client.Templates.Get(ctx, id)Get a template
client.Templates.Update(ctx, id, req)Update a template
client.Templates.Delete(ctx, id)Delete a template
client.Templates.Render(ctx, id, req)Render a template with merge data
client.Automations.List(ctx, params)List automation workflows
client.Automations.Create(ctx, req)Create an automation
client.Automations.Get(ctx, id)Get an automation
client.Automations.Update(ctx, id, req)Update an automation
client.Automations.Delete(ctx, id)Delete an automation
client.Automations.Activate(ctx, id)Activate/deactivate an automation
client.Domains.List(ctx)List sending domains
client.Domains.Create(ctx, req)Add a sending domain
client.Domains.Get(ctx, id)Get a domain
client.Domains.Verify(ctx, id)Trigger domain DNS verification
client.Domains.Delete(ctx, id)Delete a domain
client.Aliases.List(ctx, params)List email aliases
client.Aliases.Create(ctx, req)Create an alias
client.Aliases.Get(ctx, id)Get an alias
client.Aliases.Update(ctx, id, req)Update an alias
client.Aliases.Delete(ctx, id)Delete an alias
client.DedicatedIPs.List(ctx)List dedicated IPs
client.DedicatedIPs.Create(ctx, req)Purchase a dedicated IP
client.DedicatedIPs.Update(ctx, id, req)Update IP pool assignment
client.DedicatedIPs.Delete(ctx, id)Release a dedicated IP
client.ABTests.List(ctx, params)List A/B tests
client.ABTests.Create(ctx, req)Create an A/B test
client.ABTests.Get(ctx, id)Get an A/B test
client.ABTests.SetWinner(ctx, id, variant)Manually set the winning variant
client.Sandbox.Send(ctx, req)Send in sandbox mode (no real delivery)
client.Sandbox.List(ctx, params)List sandbox sent messages
client.Sandbox.Delete(ctx, id)Delete a sandbox message
client.Inbound.List(ctx, params)List inbound routing rules
client.Inbound.Create(ctx, req)Create an inbound route
client.Inbound.Get(ctx, id)Get an inbound route
client.Inbound.Delete(ctx, id)Delete an inbound route
client.Analytics.Overview(ctx, params)Get send/open/click/bounce analytics
client.Track.Event(ctx, req)Track a custom event
client.Track.Purchase(ctx, req)Track a purchase event
client.Keys.List(ctx)List API keys
client.Keys.Create(ctx, req)Create an API key
client.Keys.Get(ctx, id)Get an API key
client.Keys.Revoke(ctx, id)Revoke an API key
client.Validate.Email(ctx, address)Validate an email address
client.Webhooks.List(ctx, params)List webhooks
client.Webhooks.Create(ctx, req)Create a webhook endpoint
client.Webhooks.Get(ctx, id)Get a webhook
client.Webhooks.Update(ctx, id, req)Update a webhook
client.Webhooks.Delete(ctx, id)Delete a webhook
client.Webhooks.Test(ctx, id)Send a test event to a webhook
client.Usage.Get(ctx, params)Get API usage stats
client.Billing.Subscription(ctx)Get current subscription details
client.Billing.Checkout(ctx, req)Create a billing checkout session
client.Workspaces.List(ctx)List workspaces
client.Workspaces.Create(ctx, req)Create a workspace
client.Workspaces.Get(ctx, id)Get a workspace
client.Workspaces.Update(ctx, id, req)Update a workspace
client.Workspaces.Delete(ctx, id)Delete a workspace
client.Workspaces.ListMembers(ctx, id)List workspace members
client.Workspaces.InviteMember(ctx, id, req)Invite a member to workspace
client.Workspaces.UpdateMember(ctx, id, userID, req)Update member role
client.Workspaces.RemoveMember(ctx, id, userID)Remove a member from workspace

Examples

Webhooks

wh, _ := client.Webhooks.Create(ctx, misarmail.CreateWebhookRequest{
    URL:    "https://yourapp.com/webhooks/mail",
    Events: []string{"email.delivered", "email.opened", "email.bounced"},
})
client.Webhooks.Test(ctx, wh.ID)

Error Handling

result, err := client.Send(ctx, req)
if err != nil {
    var apiErr *misarmail.APIError
    if errors.As(err, &apiErr) {
        fmt.Printf("API error %d: %s\n", apiErr.StatusCode, apiErr.Message)
    } else {
        fmt.Printf("Network error: %v\n", err)
    }
    return
}