go-mail

A modern, idiomatic Go library for composing and sending email over SMTP with a minimal dependency footprint.

Library
Go
vv0.8.1
1,497 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
84 /100 Excellent
Development Activity 88
Maintenance 96
Community 56
Maturity 56
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
82 /100 Excellent
Architecture 82
Code Quality 88
Innovation 78
Learning Curve 80

go-mail is a comprehensive, idiomatic Go library for composing and delivering email. It combines mail message construction, MIME encoding, DKIM and S/MIME signing, and SMTP delivery into a single package built almost entirely on the Go standard library and its official extended packages, giving Go programs the capabilities of a full mail user agent without pulling in a heavy dependency tree.

Under the hood it forks and extends Go’s net/smtp package with additional authentication mechanisms (including NTLM and SCRAM-SHA-256-PLUS), concurrency-safe connection reuse, and a pluggable error registry for non-RFC-conformant servers. It supports attachments and inline embeds from files, io.Reader, or embed.FS, HTML/text templating, middleware for altering messages before send, and EML import/export for interoperability with other mail tools.

What You Get

  • A functional-options Client/Msg API for building and sending mail without constructor boilerplate
  • Support for 7 SMTP authentication mechanisms including OAuth2 (XOAUTH2), NTLM, and SCRAM-SHA-256-PLUS
  • Built-in DKIM and S/MIME (RSA and ECDSA) message signing
  • Attachment and inline-embed support from the filesystem, io.Reader, embed.FS, or fs.FS
  • HTML and text templating support via Go’s html/template and text/template
  • EML file import/export for interoperability with mail user agents

Common Use Cases

  • Sending transactional email (password resets, notifications, receipts) from a Go backend
  • Delivering DKIM- and S/MIME-signed mail for organizations with strict deliverability/compliance requirements
  • Composing and sending templated HTML emails with inline images and attachments
  • Building internal tooling or CLIs that need to send mail via SMTP, sendmail, or a UNIX domain socket
  • Testing mail delivery code with output-to-file (.eml) support instead of a live SMTP server

Under The Hood

Architecture The root mail package is built around three primary types — Client (client.go, functional-options constructor NewClient(host, opts...)), Msg (msg.go, functional-options NewMsg(opts...), holding headers, parts, and attachments), and MsgWriter (msgwriter.go, an RFC 2047/2045-aware multipart serializer with explicit header/body line-length constants). Delivery flows Msg → MsgWriter → the vendored smtp package (a fork of Go’s net/smtp), with cross-cutting concerns pulled into internal packages: internal/dkim for DKIM signing, internal/pkcs7 plus root smime.go for S/MIME signing, internal/ntlm for NTLM auth, and internal/helper for shared utilities. A Middleware interface lets third-party code transform a Msg before send, and quicksend.go’s QuickSend() composes Client and Msg into a one-shot helper for simple cases. The layering is clean and modular; the one architecturally load-bearing decision is forking net/smtp rather than wrapping it, which means any future stdlib SMTP changes must be re-ported by hand.

Tech Stack go-mail targets Go 1.25 and depends on only two modules beyond the standard library: golang.org/x/crypto (S/MIME and DKIM cryptography) and golang.org/x/text (charset/encoding handling) — an intentionally minimal footprint built on crypto/tls, mime/multipart, net/textproto, and context. It ships a Nix flake (flake.nix/flake.lock) alongside standard go build/go test tooling, with GitHub Actions CI, CodeQL static analysis, and OpenSSF Scorecard checks, plus Codecov coverage reporting and REUSE/SPDX license-header compliance across the source tree.

Code Quality The repository carries 19 _test.go files sitting alongside their corresponding implementation files (auth_test.go, client_test.go, dkim_test.go, msg_test.go, smtp/smtp_test.go, and more) using Go’s standard testing package with table-driven patterns, and codecov.yml shows coverage is tracked and gated in CI. Errors are explicit and typed rather than swallowed — senderror.go defines custom delivery error types, and functions consistently wrap errors with %w for traceability. Naming follows idiomatic Go conventions (With* functional options, Set*/Get* accessors), and every exported symbol carries dense, consistently formatted GoDoc comments describing parameters and return values. CodeQL and OpenSSF Scorecard both run on every change in addition to the test suite.

What Makes It Unique Most Go SMTP libraries either wrap the unmodified standard-library net/smtp package (missing OAuth2, NTLM, and SCRAM support) or shell out to an external sendmail binary. go-mail instead forks and extends net/smtp directly, adding concurrency-safe connection reuse, a pluggable error registry for non-RFC-conformant servers, and seven distinct SMTP authentication mechanisms — while also layering on DKIM signing, S/MIME (RSA and ECDSA) signing, DSN/MDN request headers, and EML import/export, all on top of the standard library plus two extended packages rather than a C library binding. This is deep, deliberate engineering investment in a narrow domain rather than a novel architectural paradigm.

Used by 9 apps in this directory

Vue
43%
MIT

Alexandrie

Collaboration · Knowledge Management · Note Taking

2,777

The open-source, offline-first Notion, Obsidian & Confluence alternative with multi-tenant teams, OIDC/SSO, and one-command Docker deployment.

View details
86
Repo Health
73
Technical
74
Dependency
Built with
Vue 43%
TypeScript 41%
Go 13%
Updated 2 weeks ago
Go
83%
Apache 2.0

Authelia

Authentication · Security

29,110

OpenID Certified SSO and MFA portal for securing self-hosted web applications behind reverse proxies.

View details
91
Repo Health
81
Technical
75
Dependency
Built with
Go 83%
TypeScript 15%
Updated 1 weeks ago
Go
83%
MIT

Gitea

Developer Tools · Devops · Project Management

58,194

Self-hosted DevOps in a single Go binary — Git hosting, GitHub Actions-compatible CI/CD, and 30+ package registries without any SaaS dependency.

View details
93
Repo Health
79
Technical
64
Dependency
Built with
Go 83%
Updated 1 weeks ago
Go
68%
MIT

Gogs

Developer Tools

47,840

The painless self-hosted Git service that runs on anything from a Raspberry Pi to a $5 cloud droplet, delivering GitHub-like workflows as a single Go binary.

View details
87
Repo Health
79
Technical
71
Dependency
Built with
Go 68%
Go Template 16%
Updated 4 weeks ago
Go
86%
MIT

Hatchet

AI Development · Automation · Developer Tools

8,014

A Postgres-backed orchestration engine for background tasks, AI agents, and durable workflows that replaces Redis queues and multi-datastore durable execution platforms with a single self-hostable service.

View details
88
Repo Health
83
Technical
67
Dependency
Built with
Go 86%
Updated 1 weeks ago
TypeScript
51%
Other

Mattermost

Collaboration · Devops · Team Chat

39,203

Open core, self-hosted team collaboration with chat, AI agents, voice calling, and deep DevOps integrations — all under your control.

View details
96
Repo Health
87
Technical
65
Dependency
Built with
TypeScript 51%
Go 40%
Updated 1 weeks ago
Go
74%
Other

Notifuse

Marketing

2,223

Open-source, self-hosted alternative to Mailchimp, Brevo, and Klaviyo — send newsletters and transactional emails without per-email pricing or vendor lock-in.

View details
81
Repo Health
80
Technical
66
Dependency
Built with
Go 74%
TypeScript 23%
Updated 3 weeks ago
Go
54%
AGPL 3.0

Uptrace

Devops · Monitoring

4,293

Unified open-source APM that collects OpenTelemetry traces, metrics, and logs into a single self-hosted platform backed by ClickHouse.

View details
58
Repo Health
70
Technical
65
Dependency
Built with
Go 54%
Vue 34%
Updated 1 months ago
Go
66%
AGPL 3.0

Vikunja

Project Management

5,533

Self-hosted task management with natural-language quick-add, multiple views, and a fully documented REST API — your tasks, your infrastructure, zero lock-in.

View details
86
Repo Health
81
Technical
68
Dependency
Built with
Go 66%
TypeScript 22%
Vue 10%
Updated 1 weeks ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers