mail.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package conf
  2. import (
  3. "strings"
  4. "github.com/beego/beego/v2/server/web"
  5. )
  6. type SmtpConf struct {
  7. EnableMail bool
  8. MailNumber int
  9. SmtpUserName string
  10. SmtpHost string
  11. SmtpPassword string
  12. SmtpPort int
  13. FormUserName string
  14. MailExpired int
  15. Secure string
  16. }
  17. func GetMailConfig() *SmtpConf {
  18. user_name, _ := web.AppConfig.String("smtp_user_name")
  19. password, _ := web.AppConfig.String("smtp_password")
  20. smtp_host, _ := web.AppConfig.String("smtp_host")
  21. smtp_port := web.AppConfig.DefaultInt("smtp_port", 25)
  22. form_user_name, _ := web.AppConfig.String("form_user_name")
  23. enable_mail, _ := web.AppConfig.String("enable_mail")
  24. mail_number := web.AppConfig.DefaultInt("mail_number", 5)
  25. secure := web.AppConfig.DefaultString("secure", "NONE")
  26. if secure != "NONE" && secure != "LOGIN" && secure != "SSL" {
  27. secure = "NONE"
  28. }
  29. c := &SmtpConf{
  30. EnableMail: strings.EqualFold(enable_mail, "true"),
  31. MailNumber: mail_number,
  32. SmtpUserName: user_name,
  33. SmtpHost: smtp_host,
  34. SmtpPassword: password,
  35. FormUserName: form_user_name,
  36. SmtpPort: smtp_port,
  37. Secure: secure,
  38. }
  39. return c
  40. }