Skip to content

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

License

Notifications You must be signed in to change notification settings

meehow/sendmail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go sendmail Build Status

This package implements classic, well known from PHP, method of sending emails. It's stupid simple and it works not only with Sendmail, but also with other MTAs, like Postfix or sSMTP, which provide compatibility 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,
  • just uses /usr/sbin/sendmail command which is present on most of the systems,
    • if not, just update sendmail.Binary
  • outputs emails to stdout when environment variable DEBUG is set.

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages