프로젝트
GitHub에서 보기
A simple, easy to use email library for Go (golang).
domodwyer/mailyak
소개
An elegant MIME/SMTP email library with support for attachments
생산성 및 자동화측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
Original
An elegant MIME mail library with support for attachments
A simple, easy to use email library for Go (golang).
- Full attachment support (attach anything that implements
io.Reader) - Send to multiple addresses at the same time, including BCC addresses.
- Supports composing multi-part messages (HTML and plain text emails for older clients)
- Write templates directly to the email body (implements
io.Writerfor convenience) - Production ready - several million emails sent in a production environment
- SMTP over TLS support, with automatic STARTTLS upgrades for plaintext connections
Installation
If you're using go mod:
go get -v github.com/domodwyer/mailyak/v3
Or with GOPATH:
go get -v github.com/domodwyer/mailyak
Usage
// Create a new email - specify the SMTP host:port and auth (if needed)
mail := mailyak.New("mail.host.com:25", smtp.PlainAuth("", "user", "pass", "mail.host.com"))
mail.To("[email protected]")
mail.From("[email protected]")
mail.FromName("Bananas for Friends")
mail.Subject("Business proposition")
// mail.HTML() and mail.Plain() implement io.Writer, so you can do handy things like
// parse a template directly into the email body
if err := t.ExecuteTemplate(mail.HTML(), "htmlEmail", data); err != nil {
panic(" 💣 ")
}
// Or set the body using a string setter
mail.Plain().Set("Get a real email client")
// And you're done!
if err := mail.Send(); err != nil {
panic(" 💣 ")
}
To send an attachment:
mail := mailyak.New("mail.host.com:25", smtp.PlainAuth("", "user", "pass", "mail.host.com"))
mail.To("[email protected]")
mail.From("[email protected]")
mail.Subject("I am a teapot")
mail.HTML().Set("Don't panic")
// input can be a bytes.Buffer, os.File, os.Stdin, etc.
// call multiple times to attach multiple files
mail.Attach("filename.txt", &input)
if err := mail.Send(); err != nil {
panic(" 💣 ")
}
Notes
- Why "MailYak"? Because "MailyMcMailFace" is annoyingly long to type.
- You can use a single instance of mailyak to send multiple emails after changing the to/body/whatever fields, avoiding unnecessary allocation/GC pressure.
- Attachments are read when you call
Send()to prevent holding onto multiple copies of the attachment in memory (source and email) - this means changing the attachment data between callingAttach()andSend()will change what's emailed out! - For your own sanity you should vendor this, and any other libraries when going into production.
Maintenance Status
This library is fully maintained.
The (relatively) small API/scope and many years spent maturing means it doesn't receive frequent code changes any more. Bug fixes are definitely accepted (and appreciated!), and you can consider this a stable and maintained library.
관련 프로젝트 살펴보기
불러오는 중…