net/smtp

Guided tour · Networking · pkg.go.dev →

Simple SMTP client. Frozen — the maintainers recommend an external package for anything non-trivial.

Send a single message

SendMail with PLAIN auth

auth := smtp.PlainAuth("", "user@example.com", "pw", "smtp.example.com")
err := smtp.SendMail(
    "smtp.example.com:587",
    auth,
    "from@example.com",
    []string{"to@example.com"},
    []byte("Subject: hi\r\n\r\nhello"),
)

Caveat

For reliable delivery (DKIM, retries, MIME attachments) use a third-party library or a transactional email API.