z_test.go 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. package emailer
  2. import (
  3. "log"
  4. "net/mail"
  5. "testing"
  6. "github.com/fcg-xvii/go-tools/text/config"
  7. _ "github.com/fcg-xvii/go-tools/text/config/ini"
  8. )
  9. func TestEmail(t *testing.T) {
  10. conf, err := config.FromFile("ini", "z_conf.config")
  11. if err != nil {
  12. t.Fatal(err)
  13. }
  14. from := conf.ValueDefault("from", "").(string)
  15. message := conf.ValueDefault("message", "").(string)
  16. to := conf.ValueDefault("to", "").(string)
  17. user := conf.ValueDefault("user", "").(string)
  18. password := conf.ValueDefault("password", "").(string)
  19. host := conf.ValueDefault("smtp_host", "").(string)
  20. addr := conf.ValueDefault("smtp_addr", "").(string)
  21. tls := conf.ValueDefault("tls_enabled", false).(bool)
  22. auth := PlainAuth("", user, password, host, tls)
  23. t.Log(addr, host, from, to, message)
  24. mes := NewMessage("Subj )", message)
  25. //mes.BodyContentType = "text/plain;"
  26. mes.From = mail.Address{Name: from, Address: from}
  27. mes.AddTo(mail.Address{Name: to, Address: to})
  28. log.Println(string(mes.Bytes()))
  29. if err := Send(addr, auth, mes); err != nil {
  30. t.Fatal(err)
  31. }
  32. t.Log("DONE")
  33. }