go-notificationgo-notification
Guides

SMTP Port Blocking on Cloud

Why SMTP silently fails on GCP, AWS, DigitalOcean, and Azure — and what to use instead.

The problem

Most cloud providers block outbound SMTP traffic to prevent spam from compromised instances. If you deploy a Go app that sends email over SMTP on one of these platforms, it will time out or silently fail — often only in production, while local dev works fine.

Provider status

ProviderPort 25Port 587Port 465Workaround
GCPBlocked (permanent)Usually worksUsually worksUse API-based driver
AWS EC2Blocked (can request)WorksWorksRequest removal or use SES
DigitalOceanBlocked (new accounts)WorksWorksRequest removal
AzureBlockedUsually worksUsually worksUse API-based driver
HetznerOpenOpenOpenNo issues
OVHOpenOpenOpenNo issues
Bare metalOpenOpenOpenNo issues

Provider policies change. This table is a starting point, not a contract. Always test the actual connection from the deployed environment.

The fix

Switch to an API-based email driver. API drivers use HTTPS (port 443), which is never blocked.

main.go
// ❌ SMTP — may be blocked on cloud
import "github.com/gopackx/go-notification/channel/mail/smtp"

notifier.RegisterChannel("mail", smtp.New(smtp.Config{
    Host: "smtp.gmail.com", Port: 587, /* ... */
}))

// ✅ Mailgun — uses HTTPS port 443
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"),
}))

// ✅ SendGrid — uses HTTPS port 443
// ✅ AWS SES   — uses HTTPS port 443
// ✅ Resend    — uses HTTPS port 443
// ✅ Postmark  — uses HTTPS port 443

The notification code doesn't change — only the channel registration does. That's the whole point of a unified interface.

How to detect this is your problem

  • Works on your laptop, fails in prod.
  • net.Dial to smtp.example.com:25 or :587 hangs until timeout.
  • No error from your SMTP library, just i/o timeout.

If any of those match, port blocking is almost certainly the cause.

When SMTP is still fine

  • On-premise / bare-metal servers.
  • Non-restrictive hosts (Hetzner, OVH, many European providers).
  • Local development with Mailhog or Mailpit.
  • Corporate mail servers inside a firewall.