> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mailglyph.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Emails

> Send emails and validate email addresses with the MailGlyph Go SDK.

Use a **secret key** client for all email methods.

```go theme={null}
import (
  "context"
  "os"

  mailglyph "github.com/MailGlyph/mailglyph-go"
)

client := mailglyph.New(os.Getenv("MAILGLYPH_SECRET_KEY"))
ctx := context.Background()
```

## Send with basic HTML (`Emails.Send`)

```go theme={null}
subject := "Welcome"
body := "<h1>Hello</h1><p>Your SDK setup is working.</p>"
fromName := "MailGlyph Demo"

result, err := client.Emails.Send(ctx, &mailglyph.SendEmailParams{
  To: "user@example.com",
  From: &mailglyph.Recipient{Name: &fromName, Email: "hello@your-verified-domain.com"},
  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:

```go theme={null}
_, err := client.Emails.Send(ctx, &mailglyph.SendEmailParams{
  To: []interface{}{
    "one@example.com",
    &mailglyph.Recipient{Email: "two@example.com"},
  },
  From: "hello@your-verified-domain.com",
  Subject: strPtr("Product update"),
  Body: strPtr("<p>New features are live.</p>"),
})
if err != nil {
  panic(err)
}
```

## Send with template and data

```go theme={null}
template := "tmpl_123"

_, err := client.Emails.Send(ctx, &mailglyph.SendEmailParams{
  To: "user@example.com",
  From: "hello@your-verified-domain.com",
  Template: &template,
  Data: map[string]interface{}{
    "firstName": "John",
    "plan": "premium",
  },
})
if err != nil {
  panic(err)
}
```

## Send with attachments

Attachment content should be Base64-encoded:

```go theme={null}
_, err := client.Emails.Send(ctx, &mailglyph.SendEmailParams{
  To: "user@example.com",
  From: "billing@your-verified-domain.com",
  Subject: strPtr("Your invoice"),
  Body: strPtr("<p>Invoice attached.</p>"),
  Attachments: []mailglyph.Attachment{
    {
      Filename: "invoice.pdf",
      Content: "JVBERi0xLjQKJ...",
      ContentType: "application/pdf",
    },
  },
})
if err != nil {
  panic(err)
}
```

## Send with advanced options

```go theme={null}
fromName := "Growth Team"
subscribed := true

_, err := client.Emails.Send(ctx, &mailglyph.SendEmailParams{
  To: "user@example.com",
  From: &mailglyph.Recipient{Name: &fromName, Email: "hello@your-verified-domain.com"},
  Subject: strPtr("Release notes"),
  Body: strPtr("<p>Monthly update.</p>"),
  Reply: strPtr("support@your-verified-domain.com"),
  Name: strPtr("Monthly newsletter"),
  Subscribed: &subscribed,
  Headers: map[string]string{
    "X-Campaign-Id": "monthly-2026-03",
  },
})
if err != nil {
  panic(err)
}
```

## Handle typo suggestions

```go theme={null}
verification, err := client.Emails.Verify(ctx, "user@gmial.com")
if err != nil {
  panic(err)
}

if verification.Data.IsTypo && verification.Data.SuggestedEmail != nil {
  println("Did you mean:", *verification.Data.SuggestedEmail)
}
```

```go theme={null}
func strPtr(v string) *string { return &v }
```

For bulk validation, credits, and ledger examples, see [Go Email Validation](https://docs.mailglyph.com/sdks/go/email-validation.md).

See full endpoint details in the [Send email API reference](https://docs.mailglyph.com/api-reference/public-api/sendEmail.md) and [Email Validation API reference](https://docs.mailglyph.com/api-reference/verifications/verifyEmail.md).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.