1
0

mail_test.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright 2014 beego Author. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package utils
  15. import "testing"
  16. func TestMail(t *testing.T) {
  17. config := `{"username":"astaxie@gmail.com","password":"astaxie","host":"smtp.gmail.com","port":587}`
  18. mail := NewEMail(config)
  19. if mail.Username != "astaxie@gmail.com" {
  20. t.Fatal("email parse get username error")
  21. }
  22. if mail.Password != "astaxie" {
  23. t.Fatal("email parse get password error")
  24. }
  25. if mail.Host != "smtp.gmail.com" {
  26. t.Fatal("email parse get host error")
  27. }
  28. if mail.Port != 587 {
  29. t.Fatal("email parse get port error")
  30. }
  31. mail.To = []string{"xiemengjun@gmail.com"}
  32. mail.From = "astaxie@gmail.com"
  33. mail.Subject = "hi, just from beego!"
  34. mail.Text = "Text Body is, of course, supported!"
  35. mail.HTML = "<h1>Fancy Html is supported, too!</h1>"
  36. mail.AttachFile("/Users/astaxie/github/beego/beego.go")
  37. mail.Send()
  38. }