examples/

directory
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: MIT

README

Examples

Runnable examples for github.com/NGRsoftlab/mailer. Each program is self-contained and can be executed with go run ./examples/<name>.

Configuration

All examples read SMTP settings from environment variables:

Variable Description Example
SMTP_HOST SMTP server hostname smtp.example.com
SMTP_PORT SMTP server port 587
SMTP_FROM Sender address sender@example.com
SMTP_USER Auth username (auth example only) user@example.com
SMTP_PASS Auth password (auth example only) secret
SMTP_OAUTH_TOKEN OAuth2 access token (XOAuth2 only) ya29...
AUTH_MECH plain / login / xoauth2 plain
TLS_MODE none / starttls / implicit starttls

Available examples

  • basic — plain-text message
  • html — HTML message with plain-text fallback
  • attachments — multipart/mixed with attachments
  • auth — PLAIN, LOGIN and XOAUTH2 authentication
  • tls — opportunistic STARTTLS, mandatory STARTTLS and implicit TLS
  • bulk — personalized bulk send with bounded concurrency

Run any example:

SMTP_HOST=smtp.example.com \
SMTP_PORT=587 \
SMTP_FROM=sender@example.com \
go run ./examples/basic

Note on duplication

Examples intentionally duplicate a few lines of setup boilerplate so that each file is self-contained and copy-pasteable. For real projects, extract shared configuration into your own helper.

Directories

Path Synopsis
Package main sends a message with a single attachment.
Package main sends a message with a single attachment.
Package main demonstrates the three built-in auth mechanisms.
Package main demonstrates the three built-in auth mechanisms.
Package main shows the minimal plain-text send.
Package main shows the minimal plain-text send.
Package main demonstrates personalized bulk send with bounded concurrency.
Package main demonstrates personalized bulk send with bounded concurrency.
Package main sends an HTML body with a plain-text fallback.
Package main sends an HTML body with a plain-text fallback.
Package main demonstrates the three TLS modes.
Package main demonstrates the three TLS modes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL