mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/wneessen/go-mail"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
func main() {
|
|
th := os.Getenv("TEST_HOST")
|
|
if th == "" {
|
|
fmt.Printf("$TEST_HOST env variable cannot be empty\n")
|
|
os.Exit(1)
|
|
}
|
|
|
|
fa := "Winni Neessen <wn@neessen.cloud>"
|
|
toa := "Winfried Neessen <wn@neessen.net>"
|
|
//toa = "Winfried Neessen <wneessen@arch-vm.fritz.box>"
|
|
|
|
m := mail.NewMsg()
|
|
if err := m.From(fa); err != nil {
|
|
fmt.Printf("failed to set FROM address: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
if err := m.To(toa); err != nil {
|
|
fmt.Printf("failed to set TO address: %s", err)
|
|
os.Exit(1)
|
|
}
|
|
m.Subject("This is the Subject with Umlauts: üöäß")
|
|
m.SetHeader(mail.HeaderContentLang, "de", "en", "fr", "sp", "de", "en", "fr", "sp", "de", "en", "fr",
|
|
"sp", "de", "en", "fr", "sp")
|
|
m.SetHeader(mail.HeaderListUnsubscribePost, "üüüüüüüü", "aaaaääää", "ßßßßßßßßß", "XXXXXX", "ZZZZZ", "XXXXXXXX",
|
|
"äää äää", "YYYYYY", "XXXXXX", "ZZZZZ", "üäö´")
|
|
m.SetMessageID()
|
|
m.SetDate()
|
|
m.SetBulk()
|
|
|
|
m.SetBodyWriter(mail.TypeTextPlain, func(fw io.Writer) error {
|
|
_, err := io.WriteString(fw, "This is a writer test")
|
|
return err
|
|
})
|
|
m.AddAlternativeString(mail.TypeTextHTML, "This is HTML content")
|
|
//m.Write(os.Stdout)
|
|
|
|
tu := os.Getenv("TEST_USER")
|
|
tp := os.Getenv("TEST_PASS")
|
|
c, err := mail.NewClient(th, mail.WithTLSPolicy(mail.TLSMandatory),
|
|
mail.WithSMTPAuth(mail.SMTPAuthLogin), mail.WithUsername(tu),
|
|
mail.WithPassword(tp))
|
|
if err != nil {
|
|
fmt.Printf("failed to create new client: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
if err := c.DialAndSend(m); err != nil {
|
|
fmt.Printf("failed to dial: %s\n", err)
|
|
os.Exit(1)
|
|
}
|
|
|
|
}
|