go-notificationgo-notification
Channels/Email

Mailtrap

One vendor for both testing (sandbox inbox) and production sending.

Mailtrap has two products:

  • Email Testing (Sandbox) — catches outgoing email in a fake inbox so you can inspect what your app sends without emailing real users.
  • Email Sending — a production transactional sending service, like Mailgun/SendGrid.

The go-notification driver supports both. Most teams register the sandbox inbox for dev/staging and the production sender for prod, using different env vars.

Pricing

  • Sandbox — free for up to 100 emails captured/month; paid tiers add more inboxes and higher volumes.
  • Sending — from $15/month for 10,000 emails.

Exact tiers: https://mailtrap.io/pricing.

Setup (Sandbox for testing)

  1. Create an inbox at https://mailtrap.ioEmail Testing.
  2. Copy the API credentials: Inbox ID and API Token.
main.go
import (
    "github.com/gopackx/go-notification/channel/mail"
    "github.com/gopackx/go-notification/channel/mail/mailtrap"
)

notifier.RegisterChannel(mailtrap.New(mailtrap.Config{
    Sandbox:  true,
    APIToken: os.Getenv("MAILTRAP_API_TOKEN"),
    InboxID:  1234567,
    From:     mail.Address{Name: "Acme", Address: "noreply@example.com"},
}))

Setup (Production sending)

  1. In Email Sending, add and verify your domain.
  2. Create an API key.
main.go
notifier.RegisterChannel(mailtrap.New(mailtrap.Config{
    Sandbox:  false,
    APIToken: os.Getenv("MAILTRAP_API_TOKEN"),
    From:     mail.Address{Name: "Acme", Address: "noreply@example.com"},
}))

Configuration reference

FieldTypeRequiredDescription
Sandboxboolnotrue for the sandbox inbox, false for production sending.
APITokenstringyesMailtrap API token.
InboxIDintsandboxRequired in sandbox mode. Ignored in production.
Frommail.AddressyesSender. In sandbox anything works; in prod must be verified.
Timeouttime.DurationnoHTTP timeout per send. Default: 30s.

Dev → staging → prod pattern

main.go
sandbox := os.Getenv("APP_ENV") != "production"

inboxID, _ := strconv.Atoi(os.Getenv("MAILTRAP_INBOX_ID"))

notifier.RegisterChannel(mailtrap.New(mailtrap.Config{
    Sandbox:  sandbox,
    APIToken: os.Getenv("MAILTRAP_API_TOKEN"),
    // InboxID only used in sandbox mode
    InboxID: inboxID,
    From:    mail.Address{Name: "Acme", Address: "noreply@example.com"},
}))

Troubleshooting

  • 401 on sandbox — wrong API token OR the token is for a different Mailtrap product (sending vs testing). Check the token's scope in the dashboard.
  • Emails don't appear in sandbox inbox — wrong InboxID, or mode is set to production.
  • Production send rejected — domain not verified or account still in trial.