2022-03-05 16:27:09 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"github.com/wneessen/go-mail"
|
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
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
|
|
|
|
2022-03-10 16:19:51 +01:00
|
|
|
m := mail.NewMsg()
|
|
|
|
if err := m.From(`Winni Neessen <wn@neessen.net>`); err != nil {
|
|
|
|
fmt.Printf("failed to set FROM addres: %s", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
m.ToIgnoreInvalid("test@test.de", "foo@bar.de", "blubb@blah.com")
|
|
|
|
m.CcIgnoreInvalid("cc@test.de", "bar.de", "cc@blah.com")
|
|
|
|
m.BccIgnoreInvalid("bcc@test.de", "bcc@blah.com")
|
2022-03-10 16:56:41 +01:00
|
|
|
m.SetHeader("Foo", "bar")
|
2022-03-10 16:19:51 +01:00
|
|
|
m.SetMessageID()
|
|
|
|
m.SetDate()
|
|
|
|
m.SetBulk()
|
|
|
|
m.Header()
|
|
|
|
|
2022-03-10 10:53:38 +01:00
|
|
|
c, err := mail.NewClient(th, mail.WithTimeout(time.Millisecond*500), mail.WithTLSPolicy(mail.TLSMandatory),
|
|
|
|
mail.WithSMTPAuth(mail.SMTPAuthDigestMD5), 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)
|
|
|
|
}
|
2022-03-10 16:19:51 +01:00
|
|
|
defer func() {
|
|
|
|
if err := c.Close(); err != nil {
|
|
|
|
fmt.Printf("failed to close: %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}()
|
2022-03-09 16:52:23 +01:00
|
|
|
|
2022-03-10 12:10:27 +01:00
|
|
|
if err := c.DialAndSend(); err != nil {
|
|
|
|
fmt.Printf("failed to dial: %s\n", err)
|
|
|
|
os.Exit(1)
|
|
|
|
}
|
2022-03-05 16:27:09 +01:00
|
|
|
}
|