Channels/Email
SendGrid
Send transactional email via the SendGrid v3 API.
SendGrid (Twilio SendGrid) is a mature, enterprise-grade email platform with strong compliance story (SOC 2, GDPR, HIPAA BAA available on higher tiers).
Pricing
- Free — 100 emails/day, forever.
- Essentials — from $19.95/month for 50k emails.
- Pro — from $89.95/month with dedicated IP, sub-user management.
Verify current pricing at https://sendgrid.com/pricing — tiers and limits change.
Setup
- Create an account at https://sendgrid.com.
- Complete sender authentication — either a single sender verification or full domain auth (SPF/DKIM/DMARC).
- Create an API key with at least
Mail Sendpermission.
import (
"github.com/gopackx/go-notification/channel/mail"
"github.com/gopackx/go-notification/channel/mail/sendgrid"
)
notifier.RegisterChannel(sendgrid.New(sendgrid.Config{
APIKey: os.Getenv("SENDGRID_API_KEY"),
From: mail.Address{Name: "My App", Address: "noreply@example.com"},
}))Configuration reference
| Field | Type | Required | Description |
|---|---|---|---|
APIKey | string | yes | SendGrid API key. Starts with SG.. |
From | mail.Address | yes | Verified sender (use Name for the display name). |
Timeout | time.Duration | no | HTTP timeout per send. Default: 30s. |
Sending
func (n OrderShipped) ToMail(u notification.Notifiable) *mail.Message {
return mail.NewMessage().
SetSubject("Your order shipped").
Line("Tracking inside.").
Action("Track", "https://example.com/track")
}Troubleshooting
401 Unauthorized— bad API key, or the key is missingMail Sendscope.403 Forbidden: The from address does not match a verified Sender— complete sender authentication in the SendGrid dashboard.- Emails in spam even on authenticated domain — check SendGrid's Stats → Engagement panel; high bounce or spam-complaint rates will downrank your IP reputation.