A comprehensive library for sending mails with Golang

Golang Send Emails

The main idea of this library was to provide a simple interface to send emails for authors’ JS-Mailer projects. It quickly evolved into a full-fledged mail library.

go-mail follows the idiomatic Golang style and best practice. Its only dependency is the Go Standard Library. It combines many functionalities from the standard library to give easy and convenient access to mail and SMTP-related tasks.

Parts of this library (especially some parts of msgwriter.go) have been forked/ported from the go-mail/mail respectively go-gomail/gomail which both seem not to be maintained anymore.

Golang SMTP Email Library Features

Some of the features of this golang library:

  •  Only Standard Library dependant
  •  Modern, idiomatic Go
  •  Sane and secure defaults
  •  Implicit StartTLS support with different policies
  •  Makes use of contexts for a better control flow and timeout/cancelation handling
  •  SMTP Auth support (LOGIN, PLAIN, CRAM-MD)
  •  RFC5322 compliant mail address validation
  •  Explicit SSL/TLS support
  •  Support for common mail header field generation (Message-ID, Date, Bulk-Precedence, Priority, etc.)
  •  Reusing the same SMTP connection to send multiple mails
  •  Support for attachments and inline embeds (from file system, io.Reader or embed.FS)
  •  Support for different encodings
  •  Support sending mails via a local sendmail command
  •  Support for requestng MDNs (RFC 8098) and DSNs (RFC 1891)
  •  Message object satisfies io.WriteTo and io.Reader interfaces
  •  Support for Go’s html/template and text/template (as message body, alternative part or attachment/emebed)
  •  Output to file support which allows storing mail messages as e. g. .eml files to disk to open them in a MUA

go-mail works like a programmatic email client and provides lots of methods and functionalities you would consider standard in an MUA.

Golang Email Library Examples

The package is shipped with GoDoc example code for different scenarios. Check them out on its GoDoc page

For ease of use, here is a full usage example: