email

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2016 License: Apache-2.0 Imports: 9 Imported by: 0

README

golang sample send emial package

GoDoc

requirement go 1.6 (mime.QEncoding.Encode(charset, s string))

Feature

  • send html format email
  • send email with attachment

Usage

Install go get github.com/gcloudplatform/email

func Test_Send(t *testing.T) {
	m := New("smtpip:25", "password", &mail.Address{
		Address: "account@hostname",
		Name:    "account",
	})

	var to []*mail.Address
	to = append(to, &mail.Address{
		Address: "any@someone",
		Name:    "any",
	})

	err := m.Send("email title", "<h2>email content</h2>", to)
	if err != nil {
		t.Fatalf("send error: %s", err)
	} else {
		t.Log("send ok.")
	}
}

func Test_Attach(t *testing.T) {
	m := New("smtpip:25", "password", &mail.Address{
		Address: "account@hostname",
		Name:    "account",
	})

	var to []*mail.Address
	to = append(to, &mail.Address{
		Address: "any@someone",
		Name:    "any",
	})

	attach := make([]*Attachment, 0)
	attach = append(attach, &Attachment{
		Filename: "file.pdf",
		Inline:   false,
	})
	if f1, err := ioutil.ReadFile("/go/src/github.com/gcloudplatform/email/file.pdf"); err != nil {
		t.Fatalf("read file.pdf error: %s", err)
	} else {
		attach[0].Data = f1
	}

	err := m.SendWithAttachment("email title", "<h2>email content</h2>", to, attach)
	if err != nil {
		t.Fatalf("send error: %s", err)
	} else {
		t.Log("send ok.")
	}
}

//detail see email_test.go
//ref https://github.com/scorredoira/email

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Attachment

type Attachment struct {
	Filename    string
	Data        []byte
	Inline      bool
	ContentType string
}

type Mail

type Mail struct {
	// contains filtered or unexported fields
}

func New

func New(smtpServer, password string, mailAddress *mail.Address) *Mail

func (*Mail) Send

func (self *Mail) Send(title, body string, toEmail []*mail.Address) error

func (*Mail) SendWithAttachment

func (self *Mail) SendWithAttachment(title, body string, toEmail []*mail.Address, attachment []*Attachment) error

the email format see https://support.microsoft.com/zh-cn/kb/969854 https://tools.ietf.org/html/rfc1341

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL