mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
📧 Easy to use, yet comprehensive library for sending mails with Go
https://go-mail.dev
.idea | ||
cmd | ||
.cirrus.yml | ||
.gitignore | ||
auth.go | ||
client.go | ||
client_test.go | ||
doc.go | ||
encoding.go | ||
go.mod | ||
go.sum | ||
header.go | ||
LICENSE | ||
mailmsg.go | ||
README.md | ||
tls.go |
go-mail - Simple and easy way to send mails in Go
The main idea of this library was to provide a simple interface to sending mails for my JS-Mailer project. It quickly evolved into a full-fledged mail library.
This library is "WIP" an should not be considered "production ready", yet.
go-mail follows idiomatic Go style and best practice. It's only dependency is the Go Standard Library. It combines a lot of functionality from the standard library to give easy and convenient access to mail and SMTP related tasks.
Features
Some of the features of this library:
- Only Standard Library dependant
- Modern, idiotmatic Go
- Sane and secure defaults
- SSL/TLS support
- StartTLS support with different policies
- Makes use of contexts for a better control flow and timeout/cancelation handling
- SMTP Auth support (LOGIN, PLAIN, CRAM-MD5, DIGEST-MD5)
- RFC5322 compliant mail address validation
- Support for common mail header field generation (Message-ID, Date, Bulk-Precedence, etc.)
- Reusing the same SMTP connection to send multiple mails
- Support for different encodings
- Support for attachments
- Go template support
Example
package main
import (
"context"
"fmt"
"github.com/wneessen/go-mail"
"os"
"time"
)
func main() {
c, err := mail.NewClient("mail.example.com", mail.WithTimeout(time.Millisecond*500),
mail.WithTLSPolicy(mail.TLSMandatory), mail.WithSMTPAuth(mail.SMTPAuthDigestMD5),
mail.WithUsername("tester@example.com"), mail.WithPassword("secureP4ssW0rd!"))
if err != nil {
fmt.Printf("failed to create new client: %s\n", err)
os.Exit(1)
}
defer c.Close()
if err := c.DialAndSend(); err != nil {
fmt.Printf("failed to dial: %s\n", err)
os.Exit(1)
}
}