go-notificationgo-notification
Channels/Email

SMTP

The SMTP driver — when to use it, what ports work, and the Gmail app-password walkthrough.

Cloud providers block SMTP ports

  • GCP — Port 25 blocked permanently, cannot request unblock.
  • AWS EC2 — Port 25 blocked by default, unblock requests often denied.
  • DigitalOcean — Port 25 blocked for all new accounts.
  • Azure — Port 25 blocked.

Port 587 (STARTTLS) usually works, but some providers restrict it too.

If you're deploying on cloud, use Mailgun, SendGrid, or SES instead of SMTP.

When to use SMTP

  • On-premise / bare-metal servers.
  • Corporate mail servers (Exchange, Postfix).
  • Self-hosted mail (Mailcow, iRedMail, Mail-in-a-Box).
  • Local development with Mailhog or Mailpit.
  • Non-restrictive hosts (Hetzner, OVH).

Setup

main.go
import (
    "github.com/gopackx/go-notification/channel/mail"
    "github.com/gopackx/go-notification/channel/mail/smtp"
)

notifier.RegisterChannel(smtp.New(smtp.Config{
    Host:     "smtp.gmail.com",
    Port:     587, // STARTTLS — leave TLS false; the driver upgrades automatically
    Username: "user@gmail.com",
    Password: os.Getenv("SMTP_PASSWORD"),
    From:     mail.Address{Name: "My App", Address: "noreply@example.com"},
}))

TLS field = implicit TLS (port 465)

Set TLS: true only for implicit TLS on port 465. For STARTTLS on port 587, leave TLS: false — the driver upgrades the connection automatically when the server advertises STARTTLS. Setting TLS: true on port 587 will fail the handshake.

Gmail app password

Gmail won't accept your regular password for SMTP. You need an app password:

  1. Enable 2-Step Verification on your Google account.
  2. Go to https://myaccount.google.com/apppasswords.
  3. Create a new app password, label it e.g. "go-notification".
  4. Paste the 16-character password into SMTP_PASSWORD.

Configuration reference

FieldTypeRequiredDescription
HoststringyesSMTP server hostname (e.g. smtp.gmail.com).
Portintyes587 for STARTTLS, 465 for implicit TLS, 25 for plain.
UsernamestringnoSMTP auth username. Leave empty for no auth.
PasswordstringnoSMTP auth password or app password.
AuthMechanismstringno"plain" (default) or "login".
Frommail.AddressyesDefault sender. A struct: mail.Address{Name, Address}.
TLSboolnoImplicit TLS (port 465). Leave false for STARTTLS on 587.
InsecureSkipVerifyboolnoDisable TLS cert verification. Never use in production.
Timeouttime.DurationnoConnect + handshake timeout. Default: 30s.
NamestringnoOverride the channel name (default "mail").

Troubleshooting

  • connection refused — wrong host/port, or firewall / cloud provider blocking.
  • handshake error on port 587 — you set TLS: true. Leave it false; STARTTLS upgrades automatically.
  • 535 5.7.8 — bad credentials. For Gmail, you need an app password, not your account password.
  • Works locally, fails in prod — your cloud provider is almost certainly blocking port 25/587. Switch to an API driver.