Skip to content

joegrasse/mail

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The best way to send emails in Go.

Download

go get -u github.com/joegrasse/mail

Basic Usage

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

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")
	}
}

About

The easiest way to send emails in Go.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages