Skip to content

BourgeoisBear/email.v2

Repository files navigation

email.v2

Yet another SMTP client!

GoDoc

SMTP Logging

Features

This package currently supports the following:

  • From, To, Bcc, and Cc fields
  • Email addresses in both "test@example.com" and "First Last <test@example.com>" format
  • Text and HTML Message Body
  • Attachments
  • Read Receipts
  • Custom Headers
  • SMTP Logging
  • Integrated Client Settings

Installation

go get github.com/BourgeoisBear/email.v2

Simple Usage

oCfg := SMTPClientConfig{
  Server:   "mx.test.com",
  Port:     587,
  Username: "test@test.com",
  Password: "...",
  Mode:     ModeSTARTTLS,
  // SMTPLog:  "-",  // note: uncomment to log SMTP session to STDOUT
}

oEmail := NewEmail()
oEmail.From    = "test@test.com"
oEmail.To      = []string{"test_receiver@eggplant.pro"}
oEmail.Subject = "Test Message"
oEmail.Text    = []byte("Whoomp there it is!")

E := oCfg.SimpleSend(oEmail)
if E != nil { return E }

Reasons for Fork

This is a fork of https://github.com/jordan-wright/email

  • ripped out connection pooling (sending via long-term connections to SMTP servers has not been reliable)
  • condensed multiple Send... methods into NewClient() & Send() to
    • provide a more generic way of establishing unauthenticated, SSL, and STARTTLS connections
    • send multiple messages from within a single established SMTP session
    • make direct use of outside net.Conn interfaces, so as to set dial and I/O deadlines
  • added LoginAuth authentication interface for use with Office 365
  • added TextprotoLogged for full logging of SMTP traffic

Testing

To run unit tests, add the proper credentials to email_test_settings.json for accounts you choose to test with. Examples for O365, GMAIL, & CUSTOM have been provided.