From ed9a2da83b3b77e7dd0314eaa92082ac8a2a9a9c Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Mon, 21 Sep 2015 15:11:56 -0700 Subject: Adding email to admin console --- api/admin.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'api/admin.go') diff --git a/api/admin.go b/api/admin.go index 646597755..ca66b7cb4 100644 --- a/api/admin.go +++ b/api/admin.go @@ -24,6 +24,7 @@ func InitAdmin(r *mux.Router) { sr.Handle("/config", ApiUserRequired(getConfig)).Methods("GET") sr.Handle("/save_config", ApiUserRequired(saveConfig)).Methods("POST") sr.Handle("/client_props", ApiAppHandler(getClientProperties)).Methods("GET") + sr.Handle("/test_email", ApiUserRequired(testEmail)).Methods("POST") } func getLogs(c *Context, w http.ResponseWriter, r *http.Request) { @@ -98,3 +99,29 @@ func saveConfig(c *Context, w http.ResponseWriter, r *http.Request) { json := utils.Cfg.ToJson() w.Write([]byte(json)) } + +func testEmail(c *Context, w http.ResponseWriter, r *http.Request) { + if !c.HasSystemAdminPermissions("testEmail") { + return + } + + cfg := model.ConfigFromJson(r.Body) + if cfg == nil { + c.SetInvalidParam("testEmail", "config") + return + } + + if result := <-Srv.Store.User().Get(c.Session.UserId); result.Err != nil { + c.Err = result.Err + return + } else { + if err := utils.SendMailUsingConfig(result.Data.(*model.User).Email, "Mattermost - Testing Email Settings", "


It appears your Mattermost email is setup correctly!", cfg); err != nil { + c.Err = err + return + } + } + + m := make(map[string]string) + m["SUCCESS"] = "true" + w.Write([]byte(model.MapToJson(m))) +} -- cgit v1.2.3-1-g7c22