Browse Source

Add sending test message to SMTP save settings action

Vova Tkach 5 years ago
parent
commit
52d080e80c
1 changed files with 13 additions and 0 deletions
  1. 13 0
      modules/module_settings_act_smtp.go

+ 13 - 0
modules/module_settings_act_smtp.go

@@ -17,6 +17,7 @@ func (this *Modules) RegisterAction_SettingsSmtp() *Action {
 		pf_smtp_port := strings.TrimSpace(wrap.R.FormValue("smtp-port"))
 		pf_smtp_login := strings.TrimSpace(wrap.R.FormValue("smtp-login"))
 		pf_smtp_password := strings.TrimSpace(wrap.R.FormValue("smtp-password"))
+		pf_smtp_test_email := strings.TrimSpace(wrap.R.FormValue("smtp-test-email"))
 
 		(*wrap.Config).SMTP.Host = pf_smtp_host
 		(*wrap.Config).SMTP.Port = utils.StrToInt(pf_smtp_port)
@@ -32,6 +33,18 @@ func (this *Modules) RegisterAction_SettingsSmtp() *Action {
 			return
 		}
 
+		// Send test message
+		if pf_smtp_test_email != "" {
+			if err := wrap.SendEmail(
+				pf_smtp_test_email,
+				"Fave.Pro SMTP test message",
+				"Hello! This is Fave.Pro test message.<br />If you see this message, then you right configured SMTP settings!",
+			); err != nil {
+				wrap.MsgError(err.Error())
+				return
+			}
+		}
+
 		// Reload current page
 		wrap.Write(`window.location.reload(false);`)
 	})