smtp_test.go 541 B

1234567891011121314151617181920212223242526272829
  1. package mail
  2. import (
  3. "os"
  4. "testing"
  5. )
  6. func TestSend(t *testing.T) {
  7. conf := &SMTPConfig{
  8. Username: "swh@adm***.com",
  9. Password: "",
  10. Host: "smtp.exmail.qq.com",
  11. Port: 465,
  12. Secure: "SSL",
  13. }
  14. c := NewSMTPClient(conf)
  15. m := NewMail()
  16. m.AddTo("brother <1556****@qq.com>")
  17. m.AddFrom("hank <" + conf.Username + ">")
  18. m.AddSubject("Testing")
  19. m.AddText("Some text :)")
  20. filepath, _ := os.Getwd()
  21. m.AddAttachment(filepath + "/README.md")
  22. if e := c.Send(m); e != nil {
  23. t.Error(e)
  24. } else {
  25. t.Log("发送成功")
  26. }
  27. }