smtp_test.go 905 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. })
  32. err := bf.Send(&beaconfire.BeaconParam{
  33. From: FROM,
  34. To: []string{TO},
  35. Ts: time.Now().Unix(),
  36. Title: "test",
  37. Content: "cfdfgddfdfdf",
  38. })
  39. if err != nil {
  40. t.Error(err)
  41. }
  42. }