all repos — mail2 @ 4b1c41db53f32c7e0a4aeeff9a58c5033c0b46e6

fork of github.com/joegrasse/mail with some changes

README.md (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
The best way to send emails in Go.

**Download**

```bash
go get -u github.com/joegrasse/mail
```

**Basic Usage**

```go
package main

import (
	"fmt"

	"github.com/joegrasse/mail"
)

func main() {
	err := mail.New().
		SetFrom("From Example <from@example.com>").
		AddTo("to@example.com").
		SetSubject("New Go Email").
		SetBody("text/plain", "Hello Gophers!").
		Send("smtp.example.com:25")

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Email Sent")
	}
}
```

**More Advanced Usage**

```go
package main

import (
	"fmt"

	"github.com/joegrasse/mail"
)

func main() {
	htmlBody :=
`<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>Hello Gophers!</title>
	</head>
	<body>
		<p>This is the <b>Go gopher</b>.</p>
		<p><img src="cid:Gopher.png" alt="Go gopher" /></p>
		<p>Image created by Renee French</p>
	</body>
</html>`

	email := mail.New()
	email.SetPriority(mail.PriorityHigh)
	email.SetFrom("From Example <from@example.com>").
		AddTo("to@example.com").
		AddCc("otherto@example.com").
		SetSubject("New Go Email")

	email.SetBody("text/plain", "Hello Gophers!")
	email.AddAlternative("text/html", htmlBody)

	email.AddInline("/path/to/image.png", "Gopher.png")

	err := email.Send("smtp.example.com:25")

	if err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("Email Sent")
	}
}
```