Code Monkey home page Code Monkey logo

email's Introduction

email

Build Status GoDoc

Robust and flexible email library for Go

Email for humans

The email package is designed to be simple to use, but flexible enough so as not to be restrictive. The goal is to provide an email interface for humans.

The email package currently supports the following:

  • From, To, Bcc, and Cc fields
  • Email addresses in both "[email protected]" and "First Last <[email protected]>" format
  • Text and HTML Message Body
  • Attachments
  • Read Receipts
  • Custom headers
  • More to come!

Installation

go get github.com/jordan-wright/email

Note: Version > 1 of this library requires Go v1.5 or above.

If you need compatibility with previous Go versions, you can use the previous package at gopkg.in/jordan-wright/email.v1

Examples

Sending email using Gmail

e := email.NewEmail()
e.From = "Jordan Wright <[email protected]>"
e.To = []string{"[email protected]"}
e.Bcc = []string{"[email protected]"}
e.Cc = []string{"[email protected]"}
e.Subject = "Awesome Subject"
e.Text = []byte("Text Body is, of course, supported!")
e.HTML = []byte("<h1>Fancy HTML is supported, too!</h1>")
e.Send("smtp.gmail.com:587", smtp.PlainAuth("", "[email protected]", "password123", "smtp.gmail.com"))

Another Method for Creating an Email

You can also create an email directly by creating a struct as follows:

e := &email.Email {
	To: []string{"[email protected]"},
	From: "Jordan Wright <[email protected]>",
	Subject: "Awesome Subject",
	Text: []byte("Text Body is, of course, supported!"),
	HTML: []byte("<h1>Fancy HTML is supported, too!</h1>"),
	Headers: textproto.MIMEHeader{},
}

Creating an Email From an io.Reader

You can also create an email from any type that implements the io.Reader interface by using email.NewEmailFromReader.

Attaching a File

e := NewEmail()
e.AttachFile("test.txt")

A Pool of Reusable Connections

(var ch <-chan *email.Email)
p := email.NewPool(
	"smtp.gmail.com:587",
	4,
	smtp.PlainAuth("", "[email protected]", "password123", "smtp.gmail.com"),
)
for i := 0; i < 4; i++ {
	go func() {
		for e := range ch {
			p.Send(e, 10 * time.Second)
		}
	}()
}

Documentation

http://godoc.org/github.com/jordan-wright/email

Other Sources

Sections inspired by the handy gophermail project.

Contributors

I'd like to thank all the contributors and maintainers of this package.

A special thanks goes out to Jed Denlea jeddenlea for his numerous contributions and optimizations.

email's People

Contributors

barnjamin avatar bosim avatar bughou avatar chborges avatar cristaloleg avatar diligiant avatar dmaciejak avatar fank avatar halaalajlan avatar ichinaski avatar ifraixedes avatar jeddenlea avatar jensrantil avatar jeremywohl avatar jessta avatar jordan-wright avatar knadh avatar l-ross avatar leucos avatar mgrachev avatar mjibson avatar przmv avatar quasilyte avatar rolandshoemaker avatar saromanov avatar steelphase avatar tarmo-randma avatar teepark avatar ursc avatar wscherphof avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.