smtp_test.go 901 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package providers
  2. import (
  3. "fmt"
  4. "os"
  5. "strconv"
  6. "testing"
  7. "time"
  8. "git.wenlab.co/joe/beaconfire"
  9. )
  10. func TestSmtp(t *testing.T) {
  11. host := os.Getenv("SMTP_HOST")
  12. port, _ := strconv.Atoi(os.Getenv("SMTP_PORT"))
  13. username := os.Getenv("SMTP_USERNAME")
  14. password := os.Getenv("SMTP_PASSWORD")
  15. if len(host) <= 0 || len(username) <= 0 || len(password) <= 0 {
  16. fmt.Println("SMTP env is empty")
  17. return
  18. }
  19. FROM := ""
  20. TO := ""
  21. if len(FROM) <= 0 || len(TO) <= 0 {
  22. fmt.Println("need config FROM && TO")
  23. return
  24. }
  25. bf := NewSmtp(&OptionsSmtp{
  26. Host: host,
  27. Port: port,
  28. InsecureSkipVerify: false,
  29. Username: username,
  30. Password: password,
  31. To: []string{TO},
  32. })
  33. err := bf.Send(&beaconfire.BeaconMessage{
  34. Ts: time.Now().Unix(),
  35. Title: "test",
  36. Content: "cfdfgddfdfdf",
  37. })
  38. if err != nil {
  39. t.Error(err)
  40. }
  41. }