12345678910111213141516171819202122232425262728293031323334353637 |
- package emailer
- import (
- "log"
- "net/mail"
- "testing"
- "github.com/fcg-xvii/go-tools/text/config"
- _ "github.com/fcg-xvii/go-tools/text/config/ini"
- )
- func TestEmail(t *testing.T) {
- conf, err := config.FromFile("ini", "z_conf.config")
- if err != nil {
- t.Fatal(err)
- }
- from := conf.ValueDefault("from", "").(string)
- message := conf.ValueDefault("message", "").(string)
- to := conf.ValueDefault("to", "").(string)
- user := conf.ValueDefault("user", "").(string)
- password := conf.ValueDefault("password", "").(string)
- host := conf.ValueDefault("smtp_host", "").(string)
- addr := conf.ValueDefault("smtp_addr", "").(string)
- tls := conf.ValueDefault("tls_enabled", false).(bool)
- auth := PlainAuth("", user, password, host, tls)
- t.Log(addr, host, from, to, message)
- mes := NewMessage("Subj )", message)
- //mes.BodyContentType = "text/plain;"
- mes.From = mail.Address{Name: from, Address: from}
- mes.AddTo(mail.Address{Name: to, Address: to})
- log.Println(string(mes.Bytes()))
- if err := Send(addr, auth, mes); err != nil {
- t.Fatal(err)
- }
- t.Log("DONE")
- }
|