Skip to content
goloopPublic

About

Build and send RFC 5322/MIME email over SMTP, with drop-in dev and test transports - standard library only.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Go Reference License Stay with Ukraine

mail

mail builds and sends outbound email. It is a small transport and message builder - not a marketing platform or a template engine. Zero dependencies, standard library only.

Install

go get github.com/goloop/mail

Quick start

sender := mail.NewSMTP(mail.SMTPConfig{
	Host: "smtp.example.com",
	From: mail.Address{Name: "App", Email: "no-reply@example.com"},
})

msg := mail.Message{
	To:      []mail.Address{{Email: "user@example.com"}},
	Subject: "Welcome",
	Text:    "Hello and welcome.",
	HTML:    "<p>Hello and welcome.</p>",
}

if err := sender.Send(ctx, msg); err != nil {
	return err
}

For the common case:

mail.Send(ctx, sender, "user@example.com", "Hi", "body")

Building

Set Text and/or HTML:

  • text only -> text/plain; charset=utf-8
  • HTML only -> text/html; charset=utf-8
  • both -> multipart/alternative
  • with Attachments -> multipart/mixed

Addresses are validated, display names are RFC 2047 encoded, text is quoted-printable and attachments are base64. A current Date, a random Message-ID and MIME-Version headers are added automatically.

Transports

Constructor Use
NewSMTP(SMTPConfig) production; STARTTLS (default), implicit TLS, or plain
NewLogger(io.Writer) development; writes the built message
NewCapture() tests; records messages, inspect with Last/Messages

A worker or handler depends only on the Sender interface, so dev and prod use the same code path.

Scope

mail does one send per call and returns the error. Retries, queues, templating, bounce handling and vendor APIs are out of scope: they belong to the surrounding application or its background job layer.

Documentation

License

MIT - see LICENSE.

Release v1.0.0

Encode attachments in one buffer and interrupt SMTP setup on cancellation. The v1 release keeps the existing import path and public API. Future incompatible changes require a new major version.

About

Build and send RFC 5322/MIME email over SMTP, with drop-in dev and test transports - standard library only.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages