https://github.com/meehow/sendmail
Classic, well known from PHP, method of sending emails.
https://github.com/meehow/sendmail
email go golang mail postfix sendmail ssmtp
Last synced: about 1 year ago
JSON representation
Classic, well known from PHP, method of sending emails.
- Host: GitHub
- URL: https://github.com/meehow/sendmail
- Owner: meehow
- License: gpl-3.0
- Created: 2017-08-08T19:13:41.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2021-06-05T12:37:48.000Z (about 5 years ago)
- Last Synced: 2025-03-28T23:51:14.680Z (about 1 year ago)
- Topics: email, go, golang, mail, postfix, sendmail, ssmtp
- Language: Go
- Size: 23.4 KB
- Stars: 18
- Watchers: 1
- Forks: 5
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Go sendmail [](https://travis-ci.org/meehow/sendmail)
===========
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](http://www.postfix.org/sendmail.1.html)
or [sSMTP](https://wiki.debian.org/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](https://golang.org/pkg/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
-----
```go
package main
import (
"io"
"log"
"net/mail"
"github.com/meehow/sendmail"
)
func main() {
sm := sendmail.Mail{
Subject: "Cześć",
From: &mail.Address{"Michał", "me@example.com"},
To: []*mail.Address{
{"Ktoś", "info@example.com"},
{"Ktoś2", "info2@example.com"},
},
}
io.WriteString(&sm.Text, ":)\r\n")
if err := sm.Send(); err != nil {
log.Println(err)
}
}
```
Instead of `io.WriteString`, you can [execute a template][template]:
[template]: https://golang.org/pkg/text/template/#Template.Execute
```go
tpl := template.Must(template.New("email").Parse(`Hello {{.Name}}!`))
tpl.ExecuteTemplate(&sm.Text, "email", &struct{ Name string }{"Dominik"})
```
ToDo
----
* HTML emails