go-notificationgo-notification
Channels/Email

Email Overview

Seven email drivers from self-hosted SMTP to modern APIs. Pricing, deliverability, and the cloud port-blocking caveat.

SMTP port blocking on cloud

Most cloud providers (GCP, AWS, DigitalOcean, Azure) block SMTP port 25 outbound. Port 587 is sometimes restricted too.

If you're deploying on cloud, use an API-based driver (Mailgun, SendGrid, SES, Resend, Postmark, Mailtrap) instead of SMTP. API drivers use HTTPS (port 443) which is never blocked.

See the full guide: SMTP Port Blocking on Cloud.

Driver Comparison

DriverFree TierPricingTransportBest For
SMTPSelf-hostedSMTPOn-premise, corporate mail
Mailgun100/day$0.80/1000APIStartups, dev
SendGrid100/dayFrom $19.95APIEnterprise, compliance
AWS SES3,000/mo$0.10/1000APIHigh volume, AWS-resident stacks
Resend3,000/moFrom $20APIModern developer experience
Postmark100/moFrom $15APIBest inbox deliverability
Mailtrap1,000/moFrom $15APITest + production in one vendor

Free tiers change. Check each provider's pricing page before committing.

Quick Start

main.go
import "github.com/gopackx/go-notification/channel/mail/mailgun"

notifier.RegisterChannel("mail", mailgun.New(mailgun.Config{
    Domain: "mg.example.com",
    APIKey: os.Getenv("MAILGUN_API_KEY"),
    From:   "noreply@example.com",
}))

Then return "mail" from your notification's Via() and implement ToMail():

main.go
func (n OrderShipped) Via(u notification.Notifiable) []string {
    return []string{"mail"}
}

func (n OrderShipped) ToMail(u notification.Notifiable) *mail.Message {
    return mail.NewMessage().
        Subject("Your order shipped").
        Line("Hi, your order is on its way.").
        Action("Track package", "https://example.com/track")
}

Choosing a driver

The short version:

  • Cloud deployment? Use an API driver (Mailgun, SES, Resend, Postmark).
  • Best deliverability? Postmark.
  • Cheapest at scale? AWS SES ($0.10 per 1,000).
  • Just starting? Mailgun or Resend — both have generous free tiers.
  • Testing? Mailtrap sandbox, then flip the same account to production.
  • On-premise / no cloud restrictions? SMTP is fine.

Long version with flowchart: Choosing an Email Driver.