Skip to main content
Use a secret key client for all email methods.
import (
  "context"
  "os"

  mailrify "github.com/Mailrify/mailrify-go"
)

client := mailrify.New(os.Getenv("MAILRIFY_SECRET_KEY"))
ctx := context.Background()

Send with basic HTML (Emails.Send)

subject := "Welcome"
body := "<h1>Hello</h1><p>Your SDK setup is working.</p>"
fromName := "Mailrify Demo"

result, err := client.Emails.Send(ctx, &mailrify.SendEmailParams{
  To: "[email protected]",
  From: &mailrify.Recipient{Name: &fromName, Email: "[email protected]"},
  Subject: &subject,
  Body: &body,
})
if err != nil {
  panic(err)
}

println(result.Success, result.Data.Timestamp)

Send to multiple recipients

To supports strings, recipient objects, or both:
_, err := client.Emails.Send(ctx, &mailrify.SendEmailParams{
  To: []interface{}{
    "[email protected]",
    &mailrify.Recipient{Email: "[email protected]"},
  },
  From: "[email protected]",
  Subject: strPtr("Product update"),
  Body: strPtr("<p>New features are live.</p>"),
})
if err != nil {
  panic(err)
}

Send with template and data

template := "tmpl_123"

_, err := client.Emails.Send(ctx, &mailrify.SendEmailParams{
  To: "[email protected]",
  From: "[email protected]",
  Template: &template,
  Data: map[string]interface{}{
    "firstName": "John",
    "plan": "premium",
  },
})
if err != nil {
  panic(err)
}

Send with attachments

Attachment content should be Base64-encoded:
_, err := client.Emails.Send(ctx, &mailrify.SendEmailParams{
  To: "[email protected]",
  From: "[email protected]",
  Subject: strPtr("Your invoice"),
  Body: strPtr("<p>Invoice attached.</p>"),
  Attachments: []mailrify.Attachment{
    {
      Filename: "invoice.pdf",
      Content: "JVBERi0xLjQKJ...",
      ContentType: "application/pdf",
    },
  },
})
if err != nil {
  panic(err)
}

Send with advanced options

fromName := "Growth Team"
subscribed := true

_, err := client.Emails.Send(ctx, &mailrify.SendEmailParams{
  To: "[email protected]",
  From: &mailrify.Recipient{Name: &fromName, Email: "[email protected]"},
  Subject: strPtr("Release notes"),
  Body: strPtr("<p>Monthly update.</p>"),
  Reply: strPtr("[email protected]"),
  Name: strPtr("Monthly newsletter"),
  Subscribed: &subscribed,
  Headers: map[string]string{
    "X-Campaign-Id": "monthly-2026-03",
  },
})
if err != nil {
  panic(err)
}

Verify an email address (Emails.Verify)

verification, err := client.Emails.Verify(ctx, "[email protected]")
if err != nil {
  panic(err)
}

println(verification.Data.Valid)
println(verification.Data.IsRandomInput)

Handle typo suggestions

verification, err := client.Emails.Verify(ctx, "[email protected]")
if err != nil {
  panic(err)
}

if verification.Data.IsTypo && verification.Data.SuggestedEmail != nil {
  println("Did you mean:", *verification.Data.SuggestedEmail)
}
func strPtr(v string) *string { return &v }
See full endpoint details in the Send email API reference and Verify email API reference.