go-mail/cmd/main.go

52 lines
1.4 KiB
Go
Raw Normal View History

2022-03-05 16:27:09 +01:00
package main
import (
"fmt"
"github.com/wneessen/go-mail"
"os"
)
func main() {
2022-03-07 18:14:38 +01:00
th := os.Getenv("TEST_HOST")
2022-03-09 13:20:01 +01:00
if th == "" {
fmt.Printf("$TEST_HOST env variable cannot be empty\n")
os.Exit(1)
}
2022-03-10 10:53:38 +01:00
tu := os.Getenv("TEST_USER")
tp := os.Getenv("TEST_PASS")
2022-03-10 12:10:27 +01:00
fa := "Winni Neessen <wn@neessen.cloud>"
toa := "Winfried Neessen <wn@neessen.net>"
//toa = "Winfried Neessen <wneessen@arch-vm.fritz.box>"
2022-03-10 16:19:51 +01:00
m := mail.NewMsg()
if err := m.From(fa); err != nil {
2022-03-10 16:19:51 +01:00
fmt.Printf("failed to set FROM addres: %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", "üäö´")
2022-03-10 16:19:51 +01:00
m.SetMessageID()
m.SetDate()
m.SetBulk()
c, err := mail.NewClient(th, mail.WithTLSPolicy(mail.TLSMandatory),
mail.WithSMTPAuth(mail.SMTPAuthLogin), mail.WithUsername(tu),
mail.WithPassword(tp))
2022-03-05 16:27:09 +01:00
if err != nil {
fmt.Printf("failed to create new client: %s\n", err)
os.Exit(1)
}
if err := c.DialAndSend(m); err != nil {
2022-03-10 12:10:27 +01:00
fmt.Printf("failed to dial: %s\n", err)
os.Exit(1)
}
2022-03-05 16:27:09 +01:00
}