mirror of
https://github.com/wneessen/go-mail.git
synced 2024-09-19 02:42:47 +02:00
1.5 KiB
1.5 KiB
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.
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)
}
ctx, cfn := context.WithCancel(context.Background())
defer cfn()
if err := c.DialWithContext(ctx); err != nil {
fmt.Printf("failed to dial: %s\n", err)
os.Exit(1)
}
if err := c.Send(); err != nil {
fmt.Printf("failed to send: %s\n", err)
os.Exit(1)
}
}