module_settings_act_smtp.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package modules
  2. import (
  3. "golang-fave/engine/utils"
  4. "golang-fave/engine/wrapper"
  5. )
  6. func (this *Modules) RegisterAction_SettingsSmtp() *Action {
  7. return this.newAction(AInfo{
  8. Mount: "settings-smtp",
  9. WantAdmin: true,
  10. }, func(wrap *wrapper.Wrapper) {
  11. pf_smtp_host := utils.Trim(wrap.R.FormValue("smtp-host"))
  12. pf_smtp_port := utils.Trim(wrap.R.FormValue("smtp-port"))
  13. pf_smtp_login := utils.Trim(wrap.R.FormValue("smtp-login"))
  14. pf_smtp_password := utils.Trim(wrap.R.FormValue("smtp-password"))
  15. pf_smtp_test_email := utils.Trim(wrap.R.FormValue("smtp-test-email"))
  16. (*wrap.Config).SMTP.Host = pf_smtp_host
  17. (*wrap.Config).SMTP.Port = utils.StrToInt(pf_smtp_port)
  18. (*wrap.Config).SMTP.Login = pf_smtp_login
  19. // Update password only if not empty
  20. if pf_smtp_password != "" {
  21. (*wrap.Config).SMTP.Password = pf_smtp_password
  22. }
  23. if err := wrap.ConfigSave(); err != nil {
  24. wrap.MsgError(err.Error())
  25. return
  26. }
  27. // Send test message
  28. if pf_smtp_test_email != "" {
  29. if err := wrap.SendEmailFast(
  30. pf_smtp_test_email,
  31. "❤️ Fave.Pro SMTP test message",
  32. "Hello! This is Fave.Pro test message.<br />If you see this message, then you right configured SMTP settings!",
  33. ); err != nil {
  34. wrap.MsgError(err.Error())
  35. return
  36. }
  37. }
  38. // Reload current page
  39. wrap.Write(`window.location.reload(false);`)
  40. })
  41. }