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)
- Create an inbox at https://mailtrap.io → Email Testing.
- Copy the API credentials:
Inbox IDandAPI Token.
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)
- In Email Sending, add and verify your domain.
- Create an API key.
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
| Field | Type | Required | Description |
|---|---|---|---|
Sandbox | bool | no | true for the sandbox inbox, false for production sending. |
APIToken | string | yes | Mailtrap API token. |
InboxID | int | sandbox | Required in sandbox mode. Ignored in production. |
From | mail.Address | yes | Sender. In sandbox anything works; in prod must be verified. |
Timeout | time.Duration | no | HTTP timeout per send. Default: 30s. |
Dev → staging → prod pattern
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.