Skip to content
forked from meehow/sendmail

Classic, well known from PHP, method of sending emails.

License

Notifications You must be signed in to change notification settings

digineo/sendmail

 
 

Repository files navigation

Go sendmail

GoDoc Build Status

This package implements the classic method of sending emails, well known from PHP. It's stupid simple and it works not only with Sendmail, but also with other MTAs, like Postfix, sSMTP, or mhsendmail, which provide a compatible interface.

  • it separates email headers from email body,
  • encodes UTF-8 headers like Subject, From, To
  • makes it easy to use text/template
  • doesn't require any SMTP configuration,
  • can write email body to a custom io.Writer to simplify testing
  • by default, it just uses /usr/sbin/sendmail (but can be changed if need be)

Installation

go get -u github.com/meehow/sendmail

Usage

package main

import (
	"io"
	"log"
	"net/mail"

	"github.com/meehow/sendmail"
)

func main() {
	sm := sendmail.Mail{
		Subject: "Cześć",
		From:    &mail.Address{"Michał", "[email protected]"},
		To: []*mail.Address{
			{"Ktoś", "[email protected]"},
			{"Ktoś2", "[email protected]"},
		},
	}
	io.WriteString(&sm.Text, ":)\r\n")
	if err := sm.Send(); err != nil {
		log.Println(err)
	}
}

Instead of io.WriteString, you can execute a template:

tpl := template.Must(template.New("email").Parse(`Hello {{.Name}}!`))
tpl.ExecuteTemplate(&sm.Text, "email", &struct{ Name string }{"Dominik"})

ToDo

  • HTML emails
  • multipart emails (HTML + Text)
  • attachments
  • inline attachments

About

Classic, well known from PHP, method of sending emails.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%