package actions import ( . "github.com/mickael-kerjean/filestash/server/common" "gopkg.in/gomail.v2" ) func init() { Hooks.Register.WorkflowAction(&ActionNotifyEmail{}) } type ActionNotifyEmail struct{} func (this *ActionNotifyEmail) Manifest() WorkflowSpecs { return WorkflowSpecs{ Name: "notify/email", Title: "Notify", Icon: ``, Specs: Form{ Elmnts: []FormElement{ { Name: "email", Type: "text", }, { Name: "subject", Type: "text", }, { Name: "message", Type: "long_text", }, }, }, } } func (this *ActionNotifyEmail) Execute(params map[string]string, input map[string]string) (map[string]string, error) { email := struct { Hostname string Port int Username string Password string From string To string Subject string Message string }{ Hostname: Config.Get("email.server").String(), Port: Config.Get("email.port").Int(), Username: Config.Get("email.username").String(), Password: Config.Get("email.password").String(), From: Config.Get("email.from").String(), To: params["email"], Subject: params["subject"], Message: params["message"], } m := gomail.NewMessage() m.SetHeader("From", email.From) m.SetHeader("To", email.To) m.SetHeader("Subject", email.Subject) m.SetBody("text/html", email.Message) mail := gomail.NewDialer(email.Hostname, email.Port, email.Username, email.Password) return input, mail.DialAndSend(m) }